Return From Control The Percentage Of File Upload RRS feed

  • Question

  • User-1838394278 posted

    I am trying to upload large files how can I send the percantage from my controller to my javascript for showing in my progress bar.

    JsonResult ? ContentResult ?

    in my controller I have the percentage of my file upload but can not send to my view for updating my progress bar.

    var task = 
    // Track progress of the upload
    task.Progress.ProgressChanged += (s, e) => Console.WriteLine($"Progress: {e.Percentage} %");
    // await the task to wait until upload completes and get the download url
    var downloadUrl = await task;
    Saturday, February 9, 2019 10:07 AM

All replies

  • User-474980206 posted

    you have couple options:

    1) the javascript client polls via ajax to get the status. if you use a webform you will need to update the status in a db. if its a single server, you can use a static collection. the upload call should pass a request id, and the polling will pass this request id to get the status.

    2) overkill, but many will recommend setting a signal/r connection to send the status back. in this case the upload request includes the signal/r client id to send the status to.

    3) web socket connection (just lighter than signal/r)

    4) long polling (client pull / server push). you would do the request via an iframe. the server push javascript back with a flush.  

    Saturday, February 9, 2019 7:54 PM