Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display file upload progress in progressbar - Amazon S3 bucket

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.

like image 783
user1526912 Avatar asked Sep 25 '15 21:09

user1526912


People also ask

What is the best way to ensure that all objects uploaded to an Amazon S3?

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.

Does S3 upload overwrite?

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.


1 Answers

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,

like image 139
Shekhar Pankaj Avatar answered Sep 23 '22 01:09

Shekhar Pankaj