<?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: What is the format of the file downloaded via API? in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/What-is-the-format-of-the-file-downloaded-via-API/m-p/425252#M22712</link>
    <description>&lt;P&gt;Thank you Greg,&lt;/P&gt;&lt;P&gt;The reversed&amp;nbsp;&lt;SPAN&gt;"application/octet-stream" was typo and it wasn't an issue. I found a solution. Thank you for your help!&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Sat, 30 May 2020 07:56:40 GMT</pubDate>
    <dc:creator>Inter80801</dc:creator>
    <dc:date>2020-05-30T07:56:40Z</dc:date>
    <item>
      <title>What is the format of the file downloaded via API?</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/What-is-the-format-of-the-file-downloaded-via-API/m-p/424666#M22692</link>
      <description>&lt;P&gt;I download the file through Dropbox API at the server side of my app in the following manner:&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;// setting variable for buffering&lt;BR /&gt;let &lt;/SPAN&gt;&lt;SPAN&gt;fileBuffered &lt;/SPAN&gt;= &lt;SPAN&gt;''&lt;/SPAN&gt;;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN&gt;// authentication&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;const &lt;/SPAN&gt;&lt;SPAN&gt;dropbox &lt;/SPAN&gt;= &lt;SPAN&gt;dropboxV2Api&lt;/SPAN&gt;.&lt;SPAN&gt;authenticate&lt;/SPAN&gt;({&lt;BR /&gt;   &lt;SPAN&gt;token&lt;/SPAN&gt;: &lt;SPAN&gt;process&lt;/SPAN&gt;.&lt;SPAN&gt;env&lt;/SPAN&gt;.DEV_DROPBOX_SECRET_KEY&lt;BR /&gt;});&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;// configuring parameters&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;const &lt;/SPAN&gt;&lt;SPAN&gt;params &lt;/SPAN&gt;= &lt;SPAN&gt;Object&lt;/SPAN&gt;.&lt;SPAN&gt;freeze&lt;/SPAN&gt;({&lt;BR /&gt;   &lt;SPAN&gt;resource&lt;/SPAN&gt;: &lt;SPAN&gt;"files/download"&lt;/SPAN&gt;,&lt;BR /&gt;   &lt;SPAN&gt;parameters&lt;/SPAN&gt;: {&lt;BR /&gt;      &lt;SPAN&gt;path&lt;/SPAN&gt;: &lt;SPAN&gt;`/&lt;/SPAN&gt;${customerFileFolder}&lt;SPAN&gt;/&lt;/SPAN&gt;${fileName}&lt;SPAN&gt;`&lt;BR /&gt;&lt;/SPAN&gt;   }&lt;BR /&gt;});&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN&gt;&lt;BR /&gt;// download&lt;BR /&gt;let &lt;/SPAN&gt;&lt;SPAN&gt;dropboxPromise &lt;/SPAN&gt;= &lt;SPAN&gt;new &lt;/SPAN&gt;&lt;SPAN&gt;Promise&lt;/SPAN&gt;(&lt;SPAN&gt;function &lt;/SPAN&gt;(resolve, reject) {&lt;BR /&gt;&lt;SPAN&gt;dropbox&lt;/SPAN&gt;(&lt;SPAN&gt;params&lt;/SPAN&gt;, &lt;SPAN&gt;function &lt;/SPAN&gt;(err, result) {&lt;BR /&gt;&lt;SPAN&gt;if &lt;/SPAN&gt;(err) {&lt;BR /&gt;reject(err);&lt;BR /&gt;} &lt;SPAN&gt;else &lt;/SPAN&gt;{&lt;BR /&gt;resolve(result);&lt;BR /&gt;}&lt;BR /&gt;}).&lt;SPAN&gt;on&lt;/SPAN&gt;(&lt;SPAN&gt;'data'&lt;/SPAN&gt;,&lt;SPAN&gt;function&lt;/SPAN&gt;(data) {&lt;BR /&gt;&lt;SPAN&gt;fileBuffered &lt;/SPAN&gt;+= data;&lt;BR /&gt;})&lt;/PRE&gt;&lt;P&gt;At the end of the process I get the content of the PDF file that I'm trying to download in the fileBuffered variable. The lenght of the string&amp;nbsp;(132,596 bytes) in the variable is pretty equal to the size of my PDF file (139,694 bytes). That's what I get in the debugger:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture1.JPG" style="width: 999px;"&gt;&lt;img src="https://www.dropboxforum.com/t5/image/serverpage/image-id/16011iBE6903152EABDF8F/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture1.JPG" alt="Capture1.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Now I need to download the file to a client. I assume that the file is binary and I have to convert it into base64.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;// convert to base64&lt;BR /&gt;const &lt;/SPAN&gt;&lt;SPAN&gt;file &lt;/SPAN&gt;= &lt;SPAN&gt;`data&amp;amp;colon;application/pdf;base64, &lt;/SPAN&gt;${&lt;SPAN&gt;Buffer&lt;/SPAN&gt;.&lt;SPAN&gt;from&lt;/SPAN&gt;(&lt;SPAN&gt;downloadResult&lt;/SPAN&gt;.&lt;SPAN&gt;fileBuffered&lt;/SPAN&gt;).&lt;SPAN&gt;toString&lt;/SPAN&gt;(&lt;SPAN&gt;"base64"&lt;/SPAN&gt;)}&lt;SPAN&gt;`&lt;/SPAN&gt;;&lt;BR /&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;res.&lt;SPAN&gt;setHeader&lt;/SPAN&gt;(&lt;SPAN&gt;"Content-Type"&lt;/SPAN&gt;, &lt;SPAN&gt;"application/pdf"&lt;/SPAN&gt;);&lt;BR /&gt;res.&lt;SPAN&gt;setHeader&lt;/SPAN&gt;(&lt;SPAN&gt;"Accept-Encoding"&lt;/SPAN&gt;, &lt;SPAN&gt;"base64"&lt;/SPAN&gt;);&lt;BR /&gt;res.&lt;SPAN&gt;send&lt;/SPAN&gt;(&lt;SPAN&gt;file&lt;/SPAN&gt;);&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;I get a much bigger file (252,678 bytes) on a client side and it opens as empty file in Acrobat Reader. What I'm doing wrong?&lt;/P&gt;</description>
      <pubDate>Thu, 28 May 2020 03:41:03 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/What-is-the-format-of-the-file-downloaded-via-API/m-p/424666#M22692</guid>
      <dc:creator>Inter80801</dc:creator>
      <dc:date>2020-05-28T03:41:03Z</dc:date>
    </item>
    <item>
      <title>Re: What is the format of the file downloaded via API?</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/What-is-the-format-of-the-file-downloaded-via-API/m-p/424782#M22697</link>
      <description>&lt;P&gt;&lt;A href="https://www.dropbox.com/developers/documentation/http/documentation#files-download" target="_self"&gt;The&amp;nbsp;/2/files/download endpoint&lt;/A&gt; is a &lt;A href="https://www.dropbox.com/developers/documentation/http/documentation#formats" target="_self"&gt;"content-download" style&lt;/A&gt; endpoint, meaning that when the call is successful, the requested raw file data is returned in the response body, with the corresponding "Content-Type: application/octet-stream" header.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That's what you're seeing when you print out your "fileBuffered" variable; that's the data for the requested file. (For example, "%PDF..." is the beginning of the actual PDF data.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Exactly what you do with the data from there is up to you and will depend on your app and what web framework you're using, for example, so I can't really offer exact guidance on what you should do from that point. You don't necessarily&amp;nbsp;need to re-encode it with base64&amp;nbsp;unless your use case specifically calls for it for some reason though. Perhaps for your use case you should just send&amp;nbsp;fileBuffered down, along with a&amp;nbsp;"Content-Type: application/octet-stream" header as well?&lt;/P&gt;</description>
      <pubDate>Thu, 28 May 2020 14:09:13 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/What-is-the-format-of-the-file-downloaded-via-API/m-p/424782#M22697</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2020-05-28T14:09:13Z</dc:date>
    </item>
    <item>
      <title>Re: What is the format of the file downloaded via API?</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/What-is-the-format-of-the-file-downloaded-via-API/m-p/424894#M22702</link>
      <description>&lt;P&gt;Greg, thank you for your prompt response. I fully understand that there is no issue with Dropbox API and response (let's call it fileBuffered) that I get on my server-side is accurate. Regardless is I send "Content-Type", "application/pdf" or&amp;nbsp;"Content-Type", "application/octet-stream" I get a strange response on my client-side&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture1.JPG" style="width: 827px;"&gt;&lt;img src="https://www.dropboxforum.com/t5/image/serverpage/image-id/16030i4465EF02854D6EBF/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture1.JPG" alt="Capture1.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The fileBuffered size on a server-size is&amp;nbsp;132,597. The some how it grows to 254Kb when sent to a client-side. It is clear that there is no issue with Dropbox API but maybe you know how to tacke the issue?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Server-side&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;const &lt;/SPAN&gt;&lt;SPAN&gt;file &lt;/SPAN&gt;= &lt;SPAN&gt;fileBuffered&lt;/SPAN&gt;;&lt;BR /&gt;res.&lt;SPAN&gt;setHeader&lt;/SPAN&gt;(&lt;SPAN&gt;"Content-Type"&lt;/SPAN&gt;, &lt;SPAN&gt;"application/stream-octet"&lt;/SPAN&gt;);&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;res.&lt;SPAN&gt;send&lt;/SPAN&gt;(&lt;SPAN&gt;file&lt;/SPAN&gt;);&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Client-side&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;function &lt;/SPAN&gt;&lt;SPAN&gt;documentFileDownload&lt;/SPAN&gt;(fileName) {&lt;BR /&gt;   &lt;SPAN&gt;const &lt;/SPAN&gt;&lt;SPAN&gt;ip &lt;/SPAN&gt;= &lt;SPAN&gt;location&lt;/SPAN&gt;.&lt;SPAN&gt;host&lt;/SPAN&gt;;&lt;BR /&gt;   &lt;SPAN&gt;let &lt;/SPAN&gt;&lt;SPAN&gt;request &lt;/SPAN&gt;= $.ajax({&lt;BR /&gt;      &lt;SPAN&gt;type&lt;/SPAN&gt;: &lt;SPAN&gt;"POST"&lt;/SPAN&gt;,&lt;BR /&gt;      &lt;SPAN&gt;url&lt;/SPAN&gt;: &lt;SPAN&gt;`&lt;/SPAN&gt;${&lt;SPAN&gt;http&lt;/SPAN&gt;() + &lt;SPAN&gt;ip&lt;/SPAN&gt;}&lt;SPAN&gt;/documentFileDownload`&lt;/SPAN&gt;,&lt;BR /&gt;      &lt;SPAN&gt;headers&lt;/SPAN&gt;: {&lt;BR /&gt;         &lt;SPAN&gt;"Accept"&lt;/SPAN&gt;: &lt;SPAN&gt;"application/stream-octet"&lt;BR /&gt;&lt;/SPAN&gt;      },&lt;BR /&gt;  &lt;BR /&gt;      &lt;SPAN&gt;data&lt;/SPAN&gt;: {&lt;BR /&gt;         &lt;SPAN&gt;fileName&lt;/SPAN&gt;: fileName&lt;BR /&gt;      },&lt;BR /&gt;      &lt;SPAN&gt;error&lt;/SPAN&gt;: &lt;SPAN&gt;function &lt;/SPAN&gt;(err) {&lt;BR /&gt;         &lt;SPAN&gt;console&lt;/SPAN&gt;.&lt;SPAN&gt;log&lt;/SPAN&gt;(&lt;SPAN&gt;"ERROR: " &lt;/SPAN&gt;+ err);&lt;BR /&gt;      }&lt;BR /&gt;   });&lt;BR /&gt;&lt;BR /&gt;   &lt;SPAN&gt;console&lt;/SPAN&gt;.&lt;SPAN&gt;log&lt;/SPAN&gt;(&lt;SPAN&gt;request&lt;/SPAN&gt;);&lt;BR /&gt;&lt;BR /&gt;   &lt;SPAN&gt;return &lt;/SPAN&gt;&lt;SPAN&gt;request&lt;/SPAN&gt;;&lt;BR /&gt;}&amp;nbsp;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 May 2020 20:36:30 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/What-is-the-format-of-the-file-downloaded-via-API/m-p/424894#M22702</guid>
      <dc:creator>Inter80801</dc:creator>
      <dc:date>2020-05-28T20:36:30Z</dc:date>
    </item>
    <item>
      <title>Re: What is the format of the file downloaded via API?</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/What-is-the-format-of-the-file-downloaded-via-API/m-p/425092#M22705</link>
      <description>&lt;P&gt;Unfortunately I can't provide support for that side of the operation, since it's not related to the&amp;nbsp;Dropbox API.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I do notice you reversed "application/octet-stream" as "stream-octet" in your code though.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 May 2020 14:34:16 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/What-is-the-format-of-the-file-downloaded-via-API/m-p/425092#M22705</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2020-05-29T14:34:16Z</dc:date>
    </item>
    <item>
      <title>Re: What is the format of the file downloaded via API?</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/What-is-the-format-of-the-file-downloaded-via-API/m-p/425252#M22712</link>
      <description>&lt;P&gt;Thank you Greg,&lt;/P&gt;&lt;P&gt;The reversed&amp;nbsp;&lt;SPAN&gt;"application/octet-stream" was typo and it wasn't an issue. I found a solution. Thank you for your help!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 30 May 2020 07:56:40 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/What-is-the-format-of-the-file-downloaded-via-API/m-p/425252#M22712</guid>
      <dc:creator>Inter80801</dc:creator>
      <dc:date>2020-05-30T07:56:40Z</dc:date>
    </item>
  </channel>
</rss>

