We’re Still Here to Help (Even Over the Holidays!) - find out more here.
Forum Discussion
knoppys
6 years agoExplorer | Level 3
Dropzone and Upload Sessions
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'
}
});
}
});
}
});1 Reply
- Greg-DB6 years ago
Dropbox Community Moderator
An 'incorrect_offset' error from /2/files/upload_session/append_v2 indicates that the call failed because the app supplied an incorrect "cursor.offset" value in the parameters. The app and the server need to agree about where in the upload process they are in order to upload exactly the right data.
I recommend adding some logging to determine where/when the code is using the incorrect offset.
The 'incorrect_offset' error should also include a 'correct_offset' value in the response body to indicate how far along the upload session on the server is. You can parse that out and use that to automatically restart at the correct part of the file.
By the way, I redacted it from your post, but you originally included your access token in your code. You should revoke that for your security.
About Discuss Dropbox Developer & API
Make connections with other developers
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!