-
-
Save savroff/1c8593fdcd3327748613 to your computer and use it in GitHub Desktop.
// If you want to create resumable uploading for your chunks plupload uploader | |
// you need to go in plupload.dev.js on line 1419 in xhr.onload function | |
// and change this part: | |
offset += curChunkSize; | |
file.loaded = Math.min(offset, blob.size); | |
// to this: | |
offset += curChunkSize; | |
var serverOffset = parseInt(xhr.responseText); | |
if (serverOffset > offset) { | |
offset = serverOffset; | |
} | |
file.loaded = Math.min(offset, blob.size); | |
// after it you need to setup you backend server to answer correct | |
// current size of already uploaded info in json responce | |
// and now your uploader try to upload first chunk and resume uploading from needed chunk. | |
// Enjoy :) |
Is just a simple way to create resumable uploader, as I know plupload send chunks of one file one by one. (You can see it in source code). In server realisation I'm receive files by parts and then join all parts to one file after last uploaded chunk. And for me all works great. May be you need example of server side?
thanks, how to get md5 on service?
Hi, Savroff, I am trying to create a resumable file upload using plupload. Please, I would like to see a sample of the php server code you used to achieve resumable upload in a disconnected upload scenario
@toutavous Sorry I'm use ruby server. If someone disconnected, you check last uploaded chunk number (in folder, in database it's up to you) and in first chunk uploading request return chunk number + 1. This mean you return chunk number for resuming js put it in serverOffset
and uploading move to this chunk
@Setitch after first request you can return chunk numbers for example: { last_chunk_number: 14, missed_chunk_numbers: [ 2, 3 ] }
. After it you can control in javascript what chunk you need to send (in this case 2 and 3) and after start from chunk number 15.
Thanks for this! This got me started. My server was returning a JSON object, not just an offset amount, so I modified this slightly, returning a chunkid from the server instead of offset:
var resp = JSON.parse(xhr.responseText);
serverOffset = parseInt(resp.chunkid * chunkSize);
if(serverOffset == 0)
offset += curChunkSize;
else if (serverOffset > offset) {
offset = serverOffset;
}else
{
offset = null;
}
I also set the offset to null in certain cases because that triggers the upload being complete, and without it my transfers were sometimes hanging at the end.
hi .
i think i need a server side example for you solution. i did every thing , but for resuming i have problem...i use php for my server side but i know ruby... can you show me your server side code ? @savroff
That is not good, what i would love is to send more than one chunk at time, and then join them. Already doing that but i cannot resume anything.