I would like to display file upload progress in a progress bar on my web page while uploading a file to Amazon S3 …
On my web page I select a file from a file input which calls my controller with a Ajax POST request .
In the controller I extract the file from the posted request.
var hpf = Request.Files[1];
Then I call a method that uses the AmazonS3Client..
UploadVideoMultiPart(hpf.InputStream,fileName)
This above method completes the upload to S3 perfectly fine and during that process repeatedly sends the number bytes uploaded .
public static void UploadPartProgressEventCallback(object sender, StreamTransferProgressArgs e)
{// Process event.
Var progress = (string.Format("{0}/{1}", e.TransferredBytes, totalContentLength));
}
Example:
TransferredBytes TotalBytes
8778 152652556
2562 152652556
How can I send back the data from the UploadPartProgressEventCallback to the browser without stopping the upload thread.
If I could get this data I would be able to update my progress bar.
To make sure your files and Amazon S3 buckets are secure, follow these best practices: Restrict access to your S3 resources: When using AWS, restrict access to your resources to the people that absolutely need it. Follow the principle of least privilege.
By default, when you upload the file with same name. It will overwrite the existing file. In case you want to have the previous file available, you need to enable versioning in the bucket.
You Need something to communicate between your Server to Client
SignalR is your saviour here in this situation ,with the help of SignalR you gains the ability to push the Content from server side to Clientside.
entire Documentation is here SignalR@GitHub
you can follow these
web resources as well
(assuming you have gone through above link)
Now coming back to your need ,
you can even hook SignalR broadcast ie can call client method and manage groups outside the Hub class
an example beautifully explained here In this Example
Although it will be new api to learn if you are not familiar,but trust me it won't take much time to grasp it,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With