views:

182

answers:

2

Please refer to question: http://stackoverflow.com/questions/2062852/resume-in-upload-file-control

Now to find a solution for the above question, I want to work on it and develop a user control which can resume a HTTP File Upload process.

For this, I'm going to create a temporary file on server until the upload is complete. Once the uploading is done completely then will just save it to the desired location.

The procedure I have thought of is:

  1. Create a temporary file with a unique name (may be GUID) on the server.
  2. Read a chunk of file and append it to this temp file on the server.
  3. Continue step 1 to 3 until EOF is reached.
  4. Now if the connection is lost or user clicks on pause button, the writing of file is stopped and the temporary file is not deleted.
  5. Clicking on resume again or uploading the same file again will check on the server if the file exists and user whether to resume or to overwrite. (Not sure how to check if it's the same file. Also, how to step sending the chunks from client to server.)
  6. Clicking on resume will start from where it is required to be uploaded and will append that to the file on the server. (Again not sure how to do this.)

Questions:

  1. Are these steps correct to achieve the goal? Or need some modifications?
  2. I'm not sure how to implement all these steps. :-( Need ideas, links...

Any help appreciated...

A: 

Good luck man. There's no state on the web. :)

Esteban Araya
Did u mean that it is not possible?
Manish
I can't think of an easy way to do this. Your connection may be gone if the user pauses for an extended period of time; the server will not keep an open connection forever.
Esteban Araya
Yes that is part of the question/problem. And I want to design a solution for this. See this demo: http://www.element-it.com/Examples/Ultimate/index.html. If this can be done, why can't we implement it in ASP.Net.
Manish
@Manish: That demo requires Silverlight, and that's a whole different story. Silverlight runs in the client.
Esteban Araya
A: 

What you are trying is not easy, but it is doable. Follow these guidelines :
1. Write 2 functions on the client side using ajax :
- getUploadedPortionFromServer(filename) - This will ask the server if the file exists, and it should get an xml response from the server with the following info :
boolean(exist/not exist), size(bytes), md5(string)
The function will also run an md5 on the same size it got from the server on the local file,
If the md5 is the same, you can continue sending from the point it was stopped,
elseif not the same || size == 0, start over.
- uploadFromBytes(x) - Will depend on the 1st function.
2. On the server you have to write matching functions, which will check the needed stuff, and send the response via XML to the client.
- In order to have distinct filenames, you should use some sort of user tagging.
- Are users logged in to your server? if so, use a hash of thier username appended to the
filename, this will help you distinguish between the files.
- If not, use a cookie.

eitama