In development the following code successfully uploads an image file and it's resized thumbnail
private string uploadFile(IFormFile file, FileType fileType, UserDTO userDTO)
{
try
{
var storageObject = storageClient.UploadObjectAsync(
bucket: bucketId,
objectName: getUniqueFileName(userDTO.UserId, getFileType(fileType)),
contentType: file.ContentType,
source: file.OpenReadStream(),
options: new UploadObjectOptions { PredefinedAcl = PredefinedObjectAcl.PublicRead }
);
return storageObject.Result.MediaLink;
}
catch (Exception ex)
{
logger.LogError("An error ocurred while uploading file, message: " + ex.Message);
return "";
}
}
private string uploadImageThumbnail(IFormFile file, FileType fileType, UserDTO userDTO)
{
try
{
using var resourceImage = file.OpenReadStream();
Image image = Image.FromStream(resourceImage);
Image thumb = image.GetThumbnailImage(96, 96, () => false, IntPtr.Zero);
thumb.Save(resourceImage, ImageFormat.Png);
var storageObject = storageClient.UploadObjectAsync(
bucket: bucketId,
objectName: getUniqueFileName(userDTO.UserId, getFileType(fileType)),
contentType: file.ContentType,
source: resourceImage,
options: new UploadObjectOptions { PredefinedAcl = PredefinedObjectAcl.PublicRead }
);
return storageObject.Result.MediaLink;
}
catch (Exception ex)
{
logger.LogError("An error ocurred while uploading file, message: " + ex.Message);
return "";
}
}
But for some reason I can't make this to work in production environment. In the 'production' bucket only the first file using uploadFile(file, fileType, userDTO)
is successfully saved but the thumbnail is not.
Here you can see both buckets information, as you can see they're identical.
Infrastructure in Production: .NET Core 3.1 MVC App running in App Engine Flex
Infrastructure in Development: .NET Core 3.1 MVC App running in IISExpress bundled in Visual Studio
Perhaps there is something I'm using wrong or App Engine Flexible is not capable of doing these requests for some reason?
Maybe the code can be improved of course, but what I don't understand is why in development this works but in production it does not.