Reputation: 4624
How do I upload images to S3 Asynchronously, I mean the client does not have to wait until all images are done uploading to take the user to the next page of the form.
I first upload the images to my server on a temp directory, via ajax, then when the user submit the form I take those same images and upload it to S3, this step from temp to S3 take a while.
Right now I have this logic in place and working:
//Upload img to S3
AwsHelper.UploadImage(sourceFileSmall, targetFileSmall, photo.FileNameSmall, ConfigurationManager.AppSettings["AWS_bucket_PropertyImg"]);
//delete the temp local img after upload
System.IO.File.Delete(sourceFileSmall);
//I call this method several more times, one for each image size
But this takes a while because depending on the quantity it takes up to 1 minute.
I did try Wrapping this code inside a:
Task.Factory.StartNew(() => {
AwsHelper.UploadImage(sourceFileSmall, targetFileSmall, photo.FileNameSmall, ConfigurationManager.AppSettings["AWS_bucket_PropertyImg"]);
System.IO.File.Delete(sourceFileSmall);
//I call this method several more times, one for each image size
});
It does delays execute the code asynchronously and the user is taken to the next step of the form but for some reason it does not upload the files and I don't get any exceptions either.
Upvotes: 0
Views: 52
Reputation: 269312
The TransferUtility class can provide asynchronous uploads/downloads to Amazon S3.
Upvotes: 1