<?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 does not decode the file properly after uploading from XHR in javascript in Discuss Dropbox Developer &amp; API</title>
    <link>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/Dropbox-does-not-decode-the-file-properly-after-uploading-from/m-p/336531#M536</link>
    <description>&lt;P&gt;The code from that blog post expects `file` to be a JavaScript `File` object.&lt;/P&gt;
&lt;P&gt;I'm not sure what the `event.getParam` does in your version of the code, but it appears it's not retrieving the actual `File` object, and so is instead just uploading the string representation "[object Object]" of whatever object it is returning.&lt;/P&gt;
&lt;P&gt;You should instead make sure `file` is a `File` object. For example, that might look like this, if listening to the onchange event for a file input with the id "fileInput":&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;var fileInput = document.getElementById('fileInput')&lt;/PRE&gt;
&lt;PRE&gt;var file = fileInput.files[0];&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 29 Mar 2019 15:05:17 GMT</pubDate>
    <dc:creator>Greg-DB</dc:creator>
    <dc:date>2019-03-29T15:05:17Z</dc:date>
    <item>
      <title>Dropbox does not decode the file properly after uploading from XHR in javascript</title>
      <link>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/Dropbox-does-not-decode-the-file-properly-after-uploading-from/m-p/336484#M535</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I followed the link-&amp;nbsp;&lt;A href="https://blogs.dropbox.com/developers/2016/03/how-formio-uses-dropbox-as-a-file-backend-for-javascript-apps/" target="_blank"&gt;https://blogs.dropbox.com/developers/2016/03/how-formio-uses-dropbox-as-a-file-backend-for-javascript-apps/&lt;/A&gt;&amp;nbsp;to upload a file. After it is uploaded, content is corrupted or giving [object Object]&lt;/P&gt;&lt;P&gt;here is my code -&lt;/P&gt;&lt;PRE&gt;var file = event.getParam("files");
        var xhr = new XMLHttpRequest();
        var dropboxToken='accessToken';
        xhr.upload.onprogress = function(evt) {
            var percentComplete = parseInt(100.0 * evt.loaded / evt.total);
            // Upload in progress. Do something here with the percent complete.
            console.log('completed percentage=  '+percentComplete);
        };
        
        xhr.onload = function() {
            if (xhr.status === 200) {
                var fileInfo = JSON.parse(xhr.response);
                // Upload succeeded. Do something here with the file info.
                console.log('fileinfo after successful upload--'+JSON.stringify(fileInfo));
            }
            else {
                var errorMessage = xhr.response || 'Unable to upload file';
                // Upload failed. Do something here with the error.
            }
        };
        
        xhr.open('POST', 'https://content.dropboxapi.com/2/files/upload');
        xhr.setRequestHeader('Authorization', 'Bearer ' + dropboxToken);
        xhr.setRequestHeader('Content-Type', 'application/octet-stream');
        xhr.setRequestHeader('Dropbox-API-Arg', JSON.stringify({
            path: '/' +  file[0].name,
            mode: 'add',
            autorename: true,
            mute: false
        }));
      
        xhr.send(file[0]);&lt;/PRE&gt;</description>
      <pubDate>Wed, 29 May 2019 09:05:00 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/Dropbox-does-not-decode-the-file-properly-after-uploading-from/m-p/336484#M535</guid>
      <dc:creator>sk01</dc:creator>
      <dc:date>2019-05-29T09:05:00Z</dc:date>
    </item>
    <item>
      <title>Re: Dropbox does not decode the file properly after uploading from XHR in javascript</title>
      <link>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/Dropbox-does-not-decode-the-file-properly-after-uploading-from/m-p/336531#M536</link>
      <description>&lt;P&gt;The code from that blog post expects `file` to be a JavaScript `File` object.&lt;/P&gt;
&lt;P&gt;I'm not sure what the `event.getParam` does in your version of the code, but it appears it's not retrieving the actual `File` object, and so is instead just uploading the string representation "[object Object]" of whatever object it is returning.&lt;/P&gt;
&lt;P&gt;You should instead make sure `file` is a `File` object. For example, that might look like this, if listening to the onchange event for a file input with the id "fileInput":&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;var fileInput = document.getElementById('fileInput')&lt;/PRE&gt;
&lt;PRE&gt;var file = fileInput.files[0];&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Mar 2019 15:05:17 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/Dropbox-does-not-decode-the-file-properly-after-uploading-from/m-p/336531#M536</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2019-03-29T15:05:17Z</dc:date>
    </item>
  </channel>
</rss>

