views:

126

answers:

1

I have been trying to implement an ajax-style file upload. I was wondering what we must do to report the uploading progress. I am trying to implement this in my asp.net web page.

I understand the mechanism by which we can upload a file, ajax-style, on a web page. I have been googling a lot about how to show a progress bar, but I don't see proper explanations. But I've come to understand that we have to manage this from the server-side some how. (cf http://stackoverflow.com/questions/1298565/file-upload-progress)

Any ideas/code would be appreciated. Thanx in advance.

+1  A: 

I'm not sure why you want to roll your own, as there are a number of upload controls using Ajax, Flash, Silverlight, etc. Nonetheless, the concept is all about querying for progress and returning the current state. This guy went through the same process and shows how he built a component using jQuery.

Displaying progress requires your client getting feedback from your server. This means repetitive queries to your server to get progress. Display the progress on your client using that information.

On your server, you have to not only accept the inbound file upload but also respond with the aggregate progress. It's easy if you get the Content-Length header passed along in the request; the problem lies in that you won't be able to rely on having that information. There are strategies for dealing with this, but it requires you to have code that accepts the uploaded file as you're going to have to read the inbound bits.

At this point, you have other things to care about that are well beyond the scope of a progress bar, such as dealing with large file uploads in-process of your web server (out-of-process is much less detrimental to your server.)

Because of the complexities involved, I would encourage you to find an existing component instead of creating your own.

jro
when u mean "getting feedback from your server" do u mean on the same request pipeline on which the upload happens? Is this possible?
deostroll
No, this is another request to the server -- likely a web service call -- that returns the information you need to know about upload progress. The server is responsible for knowing what stage your upload is in -- and for knowing which upload file to report back to you.
jro
what is the strategy to be used?
deostroll
Your additional questions suggest that this is something you don't want to try yourself. Get a component that already does this; you'll save yourself a lot of grief.
jro
so u mean tht u hve to track it with session variables in asp.net?
deostroll