Yolo
Im using Dropzone.js to upload files to our server in the first instance.
In the secon Im streaming the file straight to a Dreopbox App folder. These files could be as big as 5-6GB so Im using the upload_session route.
Dropzone doesnt particularly allow for changing the headers and url between chunks but Ive managed to conditionally identify the first, middle and last chunks.
My issue is that I keep getting the same error:
upload_session/append_v2 409 (incorrect_offset/)
Apologies for lengthy code. This is just a quick HTML doc with some JS.
jQuery('div#dropzone').dropzone({
//Dynamic URL
url: 'https://content.dropboxapi.com/2/files/upload_session/start',
method: 'POST',
withCredentials: false,
//Set headers for the request
headers: {
'Authorization' : 'Bearer <REDACTED>',
'Content-Type' : 'application/octet-stream',
'Dropbox-API-Arg' : JSON.stringify({close:false}),
'Cache-Control': null,
'X-Requested-With': null,
'Access-Control-Allow-Headers': null
},
//Chunking options
chunking: true,
forceChunking: true,
chunkSize: 2500000, /* Testing with a 5MB File */
retryChunks: true,
retryChunksLimit: 3,
//Handle chunks and endpoints
params: function(file, xhr, chunk){},
//Processing the que
init: function(){
dropzone = this;
this.on('uploadprogress', function(file, progress, bytesSent){
var chunks = file.upload.chunks
/**
* WHen there is only 1 chunk, save the response as the session ID
* Then update the URL and add the offset for /append_v2
*/
if (chunks.length == 1) {
//Function to get the session ID from response
sessionid = knpv_get_sessionid(file);
if (sessionid) {
//Headers
dropzone.options.url = 'https://content.dropboxapi.com/2/files/upload_session/append_v2';
dropzone.options.headers['Dropbox-API-Arg'] = JSON.stringify({
'cursor': {
'session_id': sessionid,
'offset': file.upload.bytesSent
},
'close':false
});
}
}
});
//When sending the chunk, update the URL and prams
this.on('sending', function(file, xhr, formData){
var chunks = file.upload.chunks;
/**
* All the middle chunks
*/
if (chunks.length > 1 && chunks.length < file.upload.totalChunkCount) {
/**
* Set headers
* sessionID
* offset
*/
dropzone.options.headers['Dropbox-API-Arg'] = JSON.stringify({
'cursor': {
'session_id': sessionid,
'offset': file.upload.bytesSent
},
'close': false
});
}
/**
* The final chunk
*/
if (chunks.length > 1 && chunks.length == file.upload.totalChunkCount) {
/**
* Set headers
* sessonID
* offset
* commit
*/
dropzone.options.url = 'https://content.dropboxapi.com/2/files/upload_session/finish';
dropzone.options.headers['Dropbox-API-Arg'] = JSON.stringify({
'cursor': {
'session_id': sessionid,
'offset': file.upload.bytesSent
},
'commit': {
'path': path+'/'+file.name,
'mode': 'overwrite'
}
});
}
});
}
});