<?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: Dropbox Javascript SDK - Upload sessions returns an error in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Dropbox-Javascript-SDK-Upload-sessions-returns-an-error/m-p/461035#M23661</link>
    <description>&lt;P&gt;[Cross-linking for reference:&amp;nbsp;&lt;A href="https://github.com/dropbox/dropbox-sdk-js/issues/351" target="_self"&gt;https://github.com/dropbox/dropbox-sdk-js/issues/351&lt;/A&gt; ]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for the report! I see you also posted this on GitHub. We'll look into it and follow up with you &lt;A href="https://github.com/dropbox/dropbox-sdk-js/issues/351" target="_self"&gt;there&lt;/A&gt;.&lt;/P&gt;</description>
    <pubDate>Tue, 13 Oct 2020 15:10:12 GMT</pubDate>
    <dc:creator>Greg-DB</dc:creator>
    <dc:date>2020-10-13T15:10:12Z</dc:date>
    <item>
      <title>Dropbox Javascript SDK - Upload sessions returns an error</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Dropbox-Javascript-SDK-Upload-sessions-returns-an-error/m-p/461001#M23659</link>
      <description>&lt;P&gt;Hi All&lt;/P&gt;
&lt;P&gt;Hope you can help me here, long running project.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So Im using the Dropbox SDK from github in a wordpress plugin.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A simple form which uploads files directly to a dropbox folder.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Im using the same exmaple as the JS example on the repo but I keep getting the following error when uploading chunks of large files. Always after the first upload.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Error in call to API function "files/upload_session/append:2": HTTP header "Dropbox-API-Arg": cursor: missing required field 'session_id'&lt;/PRE&gt;
&lt;P&gt;Here is the code Im using.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;var knpvDropbox = this;
        
	      const UPLOAD_FILE_SIZE_LIMIT = 50 * 1024 * 1024;
	      var ACCESS_TOKEN = 'tokenblahblahblah';
	      var dbx = new Dropbox.Dropbox({ accessToken: ACCESS_TOKEN });
	      var fileInput = document.getElementById('fileSelect');
	      var file = fileInput.files[0];
	      
	      
	      if (file.size &amp;lt; UPLOAD_FILE_SIZE_LIMIT) { // File is smaller than 150 Mb - use filesUpload API

	        dbx.filesUpload({path: knpvDropbox.folderpath + '/' +file.name, contents: file})
	          .then(function(response) {	            
	            new DropboxList(knpvDropbox.folderpath);
	            jQuery('.message-container').html(`Your upload is complete!`);
				jQuery('.modal-container').delay(2000).fadeOut();
				formvalidation.knpv_validate_dropbox();
			})
	          .catch(function(error) {
	            console.error(error);
	          });
	      } else { // File is bigger than 150 Mb - use filesUploadSession* API

	        const maxBlob = 8 * 1000 * 1000; // 8Mb - Dropbox JavaScript API suggested max file / chunk size

	        var workItems = [];     
	      
	        var offset = 0;

	        while (offset &amp;lt; file.size) {
	          var chunkSize = Math.min(maxBlob, file.size - offset);
	          workItems.push(file.slice(offset, offset + chunkSize));
	          offset += chunkSize;
	        } 
	          
	        const task = workItems.reduce((acc, blob, idx, items) =&amp;gt; {
	          if (idx == 0) {
	            // Starting multipart upload of file
	            return acc.then(function() {
	              return dbx.filesUploadSessionStart({ close: false, contents: blob})
	                        .then(response =&amp;gt; response.session_id)
	            });          
	          } else if (idx &amp;lt; items.length-1) {  
	            // Append part to the upload session
	            return acc.then(function(sessionId) {
	             var cursor = { session_id: sessionId, offset: idx * maxBlob };
	             return dbx.filesUploadSessionAppendV2({ cursor: cursor, close: false, contents: blob }).then(() =&amp;gt; sessionId); 
	            });
	          } else {
	            // Last chunk of data, close session
	            return acc.then(function(sessionId) {
	              var cursor = { session_id: sessionId, offset: file.size - blob.size };
	              var commit = { path: knpvDropbox.folderpath + '/' +file.name, mode: 'add', autorename: true, mute: false };              
	              return dbx.filesUploadSessionFinish({ cursor: cursor, commit: commit, contents: blob });           
	            });
	          }          
	        }, Promise.resolve());
	        
	        task.then(function(result) {
	        	new DropboxList(knpvDropbox.folderpath);
	          	jQuery('.message-container').html(`Your upload is complete!`);
				jQuery('.modal-container').delay(2000).fadeOut();
				formvalidation.knpv_validate_dropbox();
	        }).catch(function(error) {
	          console.error(error);
	        });
	        
	      }
	      return false;
	    }&lt;/PRE&gt;</description>
      <pubDate>Tue, 13 Oct 2020 13:27:10 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Dropbox-Javascript-SDK-Upload-sessions-returns-an-error/m-p/461001#M23659</guid>
      <dc:creator>knoppys</dc:creator>
      <dc:date>2020-10-13T13:27:10Z</dc:date>
    </item>
    <item>
      <title>Re: Dropbox Javascript SDK - Upload sessions returns an error</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Dropbox-Javascript-SDK-Upload-sessions-returns-an-error/m-p/461035#M23661</link>
      <description>&lt;P&gt;[Cross-linking for reference:&amp;nbsp;&lt;A href="https://github.com/dropbox/dropbox-sdk-js/issues/351" target="_self"&gt;https://github.com/dropbox/dropbox-sdk-js/issues/351&lt;/A&gt; ]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for the report! I see you also posted this on GitHub. We'll look into it and follow up with you &lt;A href="https://github.com/dropbox/dropbox-sdk-js/issues/351" target="_self"&gt;there&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Oct 2020 15:10:12 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Dropbox-Javascript-SDK-Upload-sessions-returns-an-error/m-p/461035#M23661</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2020-10-13T15:10:12Z</dc:date>
    </item>
  </channel>
</rss>

