HTML5 File API - slicing or not?

fabrik picture fabrik · Sep 29, 2011 · Viewed 10.3k times · Source

There are some nice examples about file uploading at HTML5 Rocks but there are something that isn't clear enough for me.

As far as i see, the example code about file slicing is getting a specific part from file then reading it. As the note says, this is helpful when we are dealing with large files.

The example about monitoring uploads also notes this is useful when we're uploading large files.

Am I safe without slicing the file? I meaning server-side problems, memory, etc. Chrome doesn't support File.slice() currently and i don't want to use a bloated jQuery plugin if possible.

Answer

ebidel picture ebidel · Oct 11, 2011

Both Chrome and FF support File.slice() but it has been prefixed as File.webkitSlice() File.mozSlice() when its semantics changed some time ago. There's another example of using it here to read part of a .zip file. The new semantics are:

Blob.webkitSlice( 
  in long long start, 
  in long long end, 
  in DOMString contentType 
); 

Are you safe without slicing it? Sure, but remember you're reading the file into memory. The HTML5Rocks tutorial offers chunking the upload as a potential performance improvement. With some decent server logic, you could also do things like recovering from a failed upload more easily. The user wouldn't have to re-try an entire 500MB file if it failed at 99% :)