locked
Asynch file upload with real time progress RRS feed

  • Question

  • User1064403333 posted

    Hi

    Using ASP.NET Web Forms, for now I want to upload a single large file with real time progress.

    The real requirement once I jump this hurdle is to upload many large files associated with many upload controls in a FormView Insert or Update event. But for now I am eliminating FormView and am just using one upload control.

    I have spent many days on this and have worked on various options.

    Option 1: Original ASP.NET File Upload Control

    The ASP.NET File Upload control renders a HTML input tag with type=”file” etc.

    Given the current HTML5 “standard”; have there been any enhancements to provide real time progress updates from the original ASP.NET File Upload Control natively?

    Option 2: AJAX Control Toolkit (ACT)

    The end user has to explicitly click Upload for each UI control . Whereas from ASP.NET FormView Insert or Update events, I do it in code behind programmatically for many different upload controls. So, not an option as far as I can see. Furthermore, I do not really want a dependency on ACT.

    Option 3: HTML5 File Input using XMLHtTTPRequest Asynchronously to an ASHX Handler

    This I can get working in terms of upload, real time progress, saving, and client response.

    However, the ASHX code is separate from an ASPX code behind. So I don’t know how I would get C# code working between ASPX code behind, and ASHX during a FormView Insert.

    Is there a way to control interflow between ASPX code behind and ASHX code before sending response back to a JavaScript client loaded event?

    Option 4: HTML5 File Input using XMLHtTTPRequest Asynchronously to an ASPX Page

    I can only get this partly working i.e. uploading with real time progress, and file save on server.

    In this option, my code  resembles sample code provided in this forum post. Except, I am using asynch i.e. I have

    xhr.open("POST", uploadServerSideScriptPath, TRUE); 

    So, where it fails is that ASPX returns the entire ASPX mark-up - which is normal behaviour; but not what the JavaScript client loaded event code is expecting. It expects plain text responseText parameter i.e. just a simple string message e.g. “Saved filename.ext”.

    Is it possible to have ASPX code behind run as usual but also return a plain text responseText to a waiting JavaScript listener function?

    Thanks for your help…

    Tuesday, December 9, 2014 1:52 AM

Answers

  • User1064403333 posted

    In case it helps anyone else.

    Option 1 - I cannot see any extra functionality in the standard ASP.NET file upload control to provide real time progress "out of the box"

    Option 2 - I did not pursue further

    Option 3 - ASPX code behind and ASHX code are separate

    Option 4 - As a work around - if sending a xhr request to an ASPX code behind, then pass in a parameter (e.g. usingASPX) to your JavaScript code that executes the xhr. Then, use this parameter as a Boolean to determine whether you should add a listener or not in your JS.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, December 21, 2014 5:39 PM

All replies

  • User1104055534 posted

    Hi,

    Please check if you can use this http://www.codeproject.com/Articles/113418/ASP-NET-File-Upload-with-Progress-Bar

    Regards, 

    Wednesday, December 17, 2014 12:23 AM
  • User1064403333 posted

    Thanks for your reply.

    I had a good look at the link suggested and it is very similar to an old Microsoft code sample I found prior to the this post.

    I find the following downsides to the suggested approach:

    • Uses old IFRAME tag and two ASPX pages, one with a web service decoration. So, having all code run sequentially in one code behind file e.g. FormView Inserting event does not seem to be possible.
    • Uses Session object which may potentially be a scalability limiting factor for very large files or number of users
    • Off beat i.e. one function polls every 500 miliseconds yet another function updates every 200 miliseconds - instead of real time in either case via XMLHTTPRequest 2
    • A minor issue - somewhat misleading function names i.e. StartProgress - also monitors progress, so perhaps it should be called MonitorProgress
    • Single file upload instead of multiple files upload

    Thanks again.

    Wednesday, December 17, 2014 6:47 PM
  • User1064403333 posted

    In case it helps anyone else.

    Option 1 - I cannot see any extra functionality in the standard ASP.NET file upload control to provide real time progress "out of the box"

    Option 2 - I did not pursue further

    Option 3 - ASPX code behind and ASHX code are separate

    Option 4 - As a work around - if sending a xhr request to an ASPX code behind, then pass in a parameter (e.g. usingASPX) to your JavaScript code that executes the xhr. Then, use this parameter as a Boolean to determine whether you should add a listener or not in your JS.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, December 21, 2014 5:39 PM