23 / resumable.js

A JavaScript library for providing multiple simultaneous, stable, fault-tolerant and resumable/restartable uploads via the HTML5 File API.
MIT License
4.66k stars 612 forks source link

Wait for the first chunk to arrive at the target before sending additional chunks #405

Open jessp01 opened 7 years ago

jessp01 commented 7 years ago

Hello all,

First of all, good job on this and thank you:)

Now on to my question: I need the first chunk to arrive BEFORE all subsequent chunks are sent and for the last one to be sent only AFTER all chunks arrived. In between, I still want several chunks to be sent in simultaneously so I do not wish to set simultaneousUploads to 1. I see there is an option called prioritizeFirstAndLastChunk: https://github.com/23/resumable.js/blob/master/resumable.js#L869 but: a. it's not exactly what I need b. even when setting it to true, on several occasions, I still get several random chunks before I get the first one

What's the best way to implement such a change to the current resumable.js code?

Thanks in advance,

bertsinnema commented 7 years ago

Why exactly would you need that functionality?

jessp01 commented 7 years ago

Hi @bertsinnema,

I am testing resumeable JS as means to upload onto the Kaltura Server, see: https://github.com/kaltura/kaltura-parallel-upload-resumablejs/

On the server side, we check whether resume was set to true: https://github.com/kaltura/server/blob/Mercury-13.3.0/alpha/apps/kaltura/lib/kUploadTokenMgr.php#L70

if so, we assume chunks of this file are already in place and we need to call the handleResume() method. If the first chunk is not the first to arrive on the server side, we'll hit: https://github.com/kaltura/server/blob/Mercury-13.3.0/alpha/apps/kaltura/lib/kUploadTokenMgr.php#L221 and the operation will fail.

Here: https://github.com/kaltura/server/blob/Mercury-13.3.0/alpha/apps/kaltura/lib/kUploadTokenMgr.php#L78 we check whether finalChunk was set to true and if so, we set the status for this upload token [which basically represents an upload "session"] to UPLOAD_TOKEN_FULL_UPLOAD. Once the status is set to that, we assume the upload was completed and therefore do no allow additional chunks to be uploaded with that particular token. And so, if the last chunk arrived before all the previous chunks were processed, the operation fails here: https://github.com/kaltura/server/blob/Mercury-13.3.0/alpha/apps/kaltura/lib/kUploadTokenMgr.php#L53

And that's basically the reason why I need this.

Thanks,

mayank-suman commented 4 years ago

I am facing the same issue. Is this resolved with any other ticket?