I am trying to take one file object and break it into pieces according to a specific block size. In my example, trying to split a single file into 1MB chunks. This way, I will find out how many pieces are needed, then I try to cut the file, starting with the "offset" (the current piece, which I find on the block size), and cuts off the size of the piece. My first fragment exits correctly at 1 MB, but my subsequent fragments turn out to be 0, any ideas why? There is a working code here:
http://codepen.io/ngalluzzo/pen/VvpYKz?editors=001[1]
var file = $('#uploadFile')[0].files[0]; var chunkSize = 1024 * 1024; var fileSize = file.size; var chunks = Math.ceil(file.size/chunkSize,chunkSize); var chunk = 0; console.log('file size..',fileSize); console.log('chunks...',chunks); while (chunk <= chunks) { var offset = chunk*chunkSize; console.log('current chunk..', chunk); console.log('offset...', chunk*chunkSize); console.log('file blob from offset...', offset) console.log(file.slice(offset,chunkSize)); chunk++; }
source share