views:

230

answers:

4

Hi,

I want a robust way to upload a file. That means that I want to be able to handle interruptions, error and pauses.

So my question is: Is something like the following possible using javascript only on the client.

If so I would like pointers to libraries, tutorials, books or implementations. If not I would like an explanation to why it's not possible.

Scenario:

  • Open a large file
  • Split it into parts

For each part I would like to

  • Create checksum and append to data
  • Post data to server (the server would check if data uploaded correctly)
  • Check a web page on server to see if upload is ok
  • If yes upload next part if no retry

Assume all posts to server is accompanied by relevant meta data (sessionid and whatnot).

+6  A: 

No. You can, through a certain amount of hackery, begin a file upload with AJAX, in which case you'll be able to tell when it's finished uploading. That's it.

JavaScript does not have any direct access to files on the visitor's computer for security reasons. The most you'll be able to see from within your script is the filename.

VoteyDisciple
+3  A: 

Firefox 3.5 adds support for DOM progress event monitoring of XMLHttpRequest transfers which allow you to keep track of at least upload status as well as completion and cancellation of uploads.

It's also possible to simulate progress tracking with iframes in clients that don't support this newer XMLHTTPRequest additions.

For an example of script that does just this, take a look at NoSWFUpload. I've been using it succesfully for about few months now.

kangax
+2  A: 

It's possible in Firefox 3 to open a local file as chosen by a file upload field and read it into a JavaScript variable using the field's files array. That would allow you to do your own chunking, hashing and sending by AJAX.

There is some talk of getting something like this standardised by W3, but for the immediate future no other browser supports this.

bobince