<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Dropzone and Upload Sessions in Discuss Dropbox Developer &amp; API</title>
    <link>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/Dropzone-and-Upload-Sessions/m-p/411239#M1131</link>
    <description>&lt;P&gt;An 'incorrect_offset' error from&amp;nbsp;/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.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I&amp;nbsp;recommend adding some logging to determine where/when the code is using the incorrect offset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The&amp;nbsp;'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.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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.&lt;/P&gt;</description>
    <pubDate>Fri, 17 Apr 2020 14:44:19 GMT</pubDate>
    <dc:creator>Greg-DB</dc:creator>
    <dc:date>2020-04-17T14:44:19Z</dc:date>
    <item>
      <title>Dropzone and Upload Sessions</title>
      <link>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/Dropzone-and-Upload-Sessions/m-p/410988#M1128</link>
      <description>&lt;P&gt;Yolo&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Im using Dropzone.js to upload files to our server in the first instance.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Dropzone doesnt particularly allow for changing the headers and url between chunks but Ive managed to conditionally identify the first, middle and last chunks.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My issue is that I keep getting the same error:&lt;/P&gt;
&lt;PRE&gt;upload_session/append_v2 409 (incorrect_offset/)&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Apologies for lengthy code. This is just a quick HTML doc with some JS.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;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 &amp;lt;REDACTED&amp;gt;',
		'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) {&lt;BR /&gt;&lt;BR /&gt;                                        //Function to get the session ID from response&lt;BR /&gt;                                        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 &amp;gt; 1 &amp;amp;&amp;amp; chunks.length &amp;lt; 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 &amp;gt; 1 &amp;amp;&amp;amp; 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'
					}
				});
			}
		
		});

	}
});&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Apr 2020 13:13:11 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/Dropzone-and-Upload-Sessions/m-p/410988#M1128</guid>
      <dc:creator>knoppys</dc:creator>
      <dc:date>2020-04-17T13:13:11Z</dc:date>
    </item>
    <item>
      <title>Re: Dropzone and Upload Sessions</title>
      <link>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/Dropzone-and-Upload-Sessions/m-p/411239#M1131</link>
      <description>&lt;P&gt;An 'incorrect_offset' error from&amp;nbsp;/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.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I&amp;nbsp;recommend adding some logging to determine where/when the code is using the incorrect offset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The&amp;nbsp;'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.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Apr 2020 14:44:19 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/Dropzone-and-Upload-Sessions/m-p/411239#M1131</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2020-04-17T14:44:19Z</dc:date>
    </item>
  </channel>
</rss>

