I'm working with a custom API to allow a user to upload a file (of, hopefully, arbitrary size). If the file is to large, it will be chunkfied, and handled in multiple requests to the server.
I'm writing code that uses File
and FileReader
(HTML5) as per many examples from online. In general (from what I read online) for a chunkfied file transfer, people will first get a blob of data from their file object
var file = $('input[type=file]')[0].files[0];
var blob = file.slice(start,end)
Then use a FileReader
to read the blob readAsArrayBuffer(blob)
or readAsBinaryString(blob)
And finally in FileReader.onload(e)
method, send the data to the server. Repeat this process for all the chunks in the file.
My questions are
Why do I need to use a FileReader
? If I don't use it, and simply send blobs with File.slice
, is there any guarantee that the slicing operation will be done before I try to send the data in each request. Does the File
object load the entire file when it's created (surely not?). Does File.slice
seek to the position stipulated by the parameters, and then read the information in? The documentation doesn't give me an clues on how it's implemented.