<?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 Unable to correctly upload images using the Dropbox API in Matlab in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Unable-to-correctly-upload-images-using-the-Dropbox-API-in/m-p/592317#M27526</link>
    <description>&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;I am trying to upload an image to Dropbox using the Dropbox API and Matlab's webwrite function.&amp;nbsp; I get a successful response when running the below code. However, the response says '&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;size: 215' when I know the size of the image should be lower than that. Furthermore, the image uploaded to Dropbox appears to be corrupted. It does not preview, and after I download and try to open the uploaded image, it does not register as a valid image. I think the issue might have something to do with the encoding, but I can't figure it out. When I use this same code to upload a plain text file with ASCII characters, it works without any problem. Does anyone know what the problem might be?&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;% Read the file from disk&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;fid = fopen(dataFile, 'r');&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;data = char(fread(fid)');&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;fclose(fid);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;[~,remoteFName, remoteExt] = fileparts(dataFile);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;headerFields = {'Authorization', ['Bearer ', dropboxAccessToken]};&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;headerFields{2,1} = 'Dropbox-API-Arg';&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;headerFields{2,2} = sprintf('{"path": "/%s%s", "mode": "add", "autorename": true, "mute": false}',remoteFName, remoteExt);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;headerFields{3,1} = 'Content-Type';&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;headerFields{3,2} = 'application/octet-stream';&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;headerFields = string(headerFields);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;% Set the options for WEBWRITE&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;opt = weboptions;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;opt.MediaType = 'application/octet-stream';&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;opt.CharacterEncoding = 'ISO-8859-1';&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;opt.RequestMethod = 'post';&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;opt.HeaderFields = headerFields;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;% Upload the file&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;try&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;tempOutput = webwrite('&lt;A href="https://content.dropboxapi.com/2/files/upload" target="_blank" rel="noopener"&gt;https://content.dropboxapi.com/2/files/upload&lt;/A&gt;', data, opt);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;catch someException&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;disp(someException);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;throw(addCause(MException('uploadToDropbox:unableToUploadFile','Unable to upload file.'),someException));&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;end&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;RESPONSE&lt;BR /&gt;&lt;BR /&gt;HTTP/1.1 200 OK&lt;BR /&gt;Cache-Control: no-cache&lt;BR /&gt;X-Content-Type-Options: nosniff&lt;BR /&gt;X-Server-Response-Time: 901&lt;BR /&gt;Content-Type: application/json&lt;BR /&gt;Accept-Encoding: identity,gzip&lt;BR /&gt;Date: Thu, 21 Apr 2022 01:25:01 GMT&lt;BR /&gt;Server: envoy&lt;BR /&gt;Strict-Transport-Security: max-age=31536000; includeSubDomains; preload&lt;BR /&gt;X-Robots-Tag: noindex, nofollow, noimageindex&lt;BR /&gt;Content-Encoding: gzip&lt;BR /&gt;Vary: Accept-Encoding&lt;BR /&gt;X-Dropbox-Response-Origin: far_remote&lt;BR /&gt;X-Dropbox-Request-Id: 12cee658f5604167905348fd834c35d5&lt;BR /&gt;Transfer-Encoding: chunked&lt;BR /&gt;&lt;BR /&gt;name: 'swiss.png'&lt;BR /&gt;path_lower: '/swiss.png'&lt;BR /&gt;path_display: '/swiss.png'&lt;BR /&gt;id: 'id:B71uxiCfSp4AAAAAAAAAOQ'&lt;BR /&gt;client_modified: '2022-04-21T01:25:00Z'&lt;BR /&gt;server_modified: '2022-04-21T01:25:01Z'&lt;BR /&gt;rev: '015dd1ffa916ba20000000266082110'&lt;BR /&gt;size: 215&lt;BR /&gt;is_downloadable: 1&lt;BR /&gt;content_hash: 'e87f106dcb11834c94b28b84ac739413b24390fae01127db49b81dcad29c62ae'&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
    <pubDate>Thu, 21 Apr 2022 01:31:57 GMT</pubDate>
    <dc:creator>reseda333</dc:creator>
    <dc:date>2022-04-21T01:31:57Z</dc:date>
    <item>
      <title>Unable to correctly upload images using the Dropbox API in Matlab</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Unable-to-correctly-upload-images-using-the-Dropbox-API-in/m-p/592317#M27526</link>
      <description>&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;I am trying to upload an image to Dropbox using the Dropbox API and Matlab's webwrite function.&amp;nbsp; I get a successful response when running the below code. However, the response says '&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;size: 215' when I know the size of the image should be lower than that. Furthermore, the image uploaded to Dropbox appears to be corrupted. It does not preview, and after I download and try to open the uploaded image, it does not register as a valid image. I think the issue might have something to do with the encoding, but I can't figure it out. When I use this same code to upload a plain text file with ASCII characters, it works without any problem. Does anyone know what the problem might be?&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;% Read the file from disk&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;fid = fopen(dataFile, 'r');&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;data = char(fread(fid)');&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;fclose(fid);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;[~,remoteFName, remoteExt] = fileparts(dataFile);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;headerFields = {'Authorization', ['Bearer ', dropboxAccessToken]};&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;headerFields{2,1} = 'Dropbox-API-Arg';&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;headerFields{2,2} = sprintf('{"path": "/%s%s", "mode": "add", "autorename": true, "mute": false}',remoteFName, remoteExt);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;headerFields{3,1} = 'Content-Type';&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;headerFields{3,2} = 'application/octet-stream';&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;headerFields = string(headerFields);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;% Set the options for WEBWRITE&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;opt = weboptions;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;opt.MediaType = 'application/octet-stream';&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;opt.CharacterEncoding = 'ISO-8859-1';&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;opt.RequestMethod = 'post';&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;opt.HeaderFields = headerFields;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;% Upload the file&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;try&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;tempOutput = webwrite('&lt;A href="https://content.dropboxapi.com/2/files/upload" target="_blank" rel="noopener"&gt;https://content.dropboxapi.com/2/files/upload&lt;/A&gt;', data, opt);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;catch someException&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;disp(someException);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;throw(addCause(MException('uploadToDropbox:unableToUploadFile','Unable to upload file.'),someException));&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;end&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;RESPONSE&lt;BR /&gt;&lt;BR /&gt;HTTP/1.1 200 OK&lt;BR /&gt;Cache-Control: no-cache&lt;BR /&gt;X-Content-Type-Options: nosniff&lt;BR /&gt;X-Server-Response-Time: 901&lt;BR /&gt;Content-Type: application/json&lt;BR /&gt;Accept-Encoding: identity,gzip&lt;BR /&gt;Date: Thu, 21 Apr 2022 01:25:01 GMT&lt;BR /&gt;Server: envoy&lt;BR /&gt;Strict-Transport-Security: max-age=31536000; includeSubDomains; preload&lt;BR /&gt;X-Robots-Tag: noindex, nofollow, noimageindex&lt;BR /&gt;Content-Encoding: gzip&lt;BR /&gt;Vary: Accept-Encoding&lt;BR /&gt;X-Dropbox-Response-Origin: far_remote&lt;BR /&gt;X-Dropbox-Request-Id: 12cee658f5604167905348fd834c35d5&lt;BR /&gt;Transfer-Encoding: chunked&lt;BR /&gt;&lt;BR /&gt;name: 'swiss.png'&lt;BR /&gt;path_lower: '/swiss.png'&lt;BR /&gt;path_display: '/swiss.png'&lt;BR /&gt;id: 'id:B71uxiCfSp4AAAAAAAAAOQ'&lt;BR /&gt;client_modified: '2022-04-21T01:25:00Z'&lt;BR /&gt;server_modified: '2022-04-21T01:25:01Z'&lt;BR /&gt;rev: '015dd1ffa916ba20000000266082110'&lt;BR /&gt;size: 215&lt;BR /&gt;is_downloadable: 1&lt;BR /&gt;content_hash: 'e87f106dcb11834c94b28b84ac739413b24390fae01127db49b81dcad29c62ae'&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 21 Apr 2022 01:31:57 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Unable-to-correctly-upload-images-using-the-Dropbox-API-in/m-p/592317#M27526</guid>
      <dc:creator>reseda333</dc:creator>
      <dc:date>2022-04-21T01:31:57Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to correctly upload images using the Dropbox API in Matlab</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Unable-to-correctly-upload-images-using-the-Dropbox-API-in/m-p/592396#M27535</link>
      <description>&lt;P&gt;The Dropbox API will save whatever data you supply in the HTTPS request body for the upload call as the file data, so you'll need to make sure you're sending the exact correct binary data that you want to store.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the code you shared here, that seems to be your "data" variable. Make sure that variable contains the data you expect to be sending.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We can't officially provide support for third party platforms like MATLAB, as that's not made by Dropbox, but looking at the rest of your code, I recommend investigating the use of the fopen, fread, and char methods. For instance, is that char method call needed/correct? It looks like it may be modifying the data you mean to send.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Apr 2022 11:55:51 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Unable-to-correctly-upload-images-using-the-Dropbox-API-in/m-p/592396#M27535</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2022-04-21T11:55:51Z</dc:date>
    </item>
  </channel>
</rss>

