cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Find out how Tiffany, a Customer Experience superstar uses Dropbox to keep her family in the loop when it comes to her new baby here!

Discuss Dropbox Developer & API

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Dropzone and Upload Sessions

Dropzone and Upload Sessions

knoppys
Explorer | Level 3

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 1

Re: Dropzone and Upload Sessions

Greg-DB
Dropboxer

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.

Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropboxer
What do Dropbox user levels mean?
Need more support?