private async Task <string> UploadFileToS3(Stream fileStream, int forroLevelId, string forroLevelName, string imageUrl, UrlOrThumbNail urlOrThumbNail) { //If there is a file being uploaded if (fileStream != null) { var fileExtension = Path.GetExtension(imageUrl); var objectKey = GetNewImageUrlObjectKey(forroLevelId, forroLevelName, urlOrThumbNail, fileExtension); //var stream = new FileStream(); var request = new PutObjectRequest() { Key = objectKey, BucketName = _bucketName, InputStream = fileStream }; await _amazonS3.PutObjectAsync(request); return(objectKey); } return(""); }
private string GetNewImageUrlObjectKey(int forroLevelId, string forroLevelName, UrlOrThumbNail urlOrThumbNail, string fileExtension) { var result = Regex.Replace(forroLevelName.Trim(), "[^a-zA-Z0-9_.]+", "-", RegexOptions.Compiled); result = forroLevelId + "-" + result.ToLower() + "-" + urlOrThumbNail.ToString().ToLower(); result = result + fileExtension; result = _forroLevelFolder + result; return(result); }