<?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: Empty files on upload in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Empty-files-on-upload/m-p/509086#M25127</link>
    <description>&lt;P&gt;[Cross-linking for reference:&amp;nbsp;&lt;A href="https://stackoverflow.com/questions/66862389/image-upload-to-dropbox-api-from-ios-sends-corrupted-file-to-dropbox" target="_blank"&gt;https://stackoverflow.com/questions/66862389/image-upload-to-dropbox-api-from-ios-sends-corrupted-file-to-dropbox&lt;/A&gt;&amp;nbsp;]&lt;/P&gt;
&lt;P&gt;The&amp;nbsp;&lt;A href="https://www.dropbox.com/developers/documentation/http/documentation#files-upload" target="_self"&gt;/2/files/upload endpoint&lt;/A&gt; is a&amp;nbsp;&lt;A href="https://www.dropbox.com/developers/documentation/http/documentation#formats" target="_self"&gt;"content-upload" style&lt;/A&gt; endpoint, meaning that it requires the file data to be uploaded in the request body. I see you're attempting to set the file data as such by using the "body" parameter in your "requestOptions" that you pass to "fetch".&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That seems correct, but you'll need to make sure your "file" variable contains the actual file data you want to upload.&lt;/P&gt;
&lt;P&gt;I understand you currently just have the URL for local file data though; not the file data itself. You'll need to read the data from the local filesystem in order to pass the data along. I'm afraid I can't offer much guidance on doing so though as that's not related to the&amp;nbsp;Dropbox API itself. You may need to refer to the relevant iOS documentation from Apple (or otherwise React/Expo if they offer functionality for this).&lt;/P&gt;</description>
    <pubDate>Tue, 30 Mar 2021 17:23:11 GMT</pubDate>
    <dc:creator>Greg-DB</dc:creator>
    <dc:date>2021-03-30T17:23:11Z</dc:date>
    <item>
      <title>Empty files on upload</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Empty-files-on-upload/m-p/509069#M25123</link>
      <description>&lt;P&gt;I have seen that this issue has been presented a few times before however, those solutions haven't helped in completed this last task for my app.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using React Native with Expo.&amp;nbsp; I am using Image Picker to select an image from iOS, and getting the uri suck as&amp;nbsp;'file:///var/mobile/Containers/Data/Application/9A9F8016-CB14-4772-BF42-91DC74EA40CC/Library/Caches/ExponentExperienceData/%2540anonymous%252Fheritagefilmsapp-5de39698-e6f1-4070-83cc-562fa650fca5/ImagePicker/855BDF4B-97F3-413C-BADA-F278CE645FAE.png'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think I need to convert the uri image into binary data but for the life of me don't understand how to do that.&lt;/P&gt;&lt;P&gt;This is my useEffect hook to upload the image:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;useEffect(() =&amp;gt; {
if (!image) {
return;
}
function http_header_safe_json(v) {
return JSON.stringify(v);
}
var myHeaders = new Headers();
myHeaders.append(
"Authorization",
"Bearer TOKEN"
);
myHeaders.append(
"Dropbox-API-Arg",
http_header_safe_json({
path: `/${user.username}/!UserUploaded_1234.${fileType}`,
mode: {
".tag": "add",
},
autorename: true,
})
);
myHeaders.append("Content-Type", "application/octet-stream");
var file = imageData;

var requestOptions = {
method: "POST",
headers: myHeaders,
body: file,
redirect: "follow",
};

fetch("https://content.dropboxapi.com/2/files/upload", requestOptions)
.then((response) =&amp;gt; response.json())
.then((result) =&amp;gt; {
console.log(result);
})
.catch((error) =&amp;gt; console.log("error", error));
}, [imageData]);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my function to grab the uri:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const chooseFromLibrary = async () =&amp;gt; {
    let result = await ImagePicker.launchImageLibraryAsync({
      mediaTypes: ImagePicker.MediaTypeOptions.All,
      allowsEditing: true,
      aspect: [4, 3],
      quality: 1,
      base64: true,
    });
    if (!result.cancelled) {
      setImage(result.uri);
      let cut = result.uri.split(".");
      setImageData(result.uri);
      setFileType(cut.pop());
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&amp;nbsp;Any help on this would be greatly appreciated.&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 30 Mar 2021 16:21:23 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Empty-files-on-upload/m-p/509069#M25123</guid>
      <dc:creator>gmacerola</dc:creator>
      <dc:date>2021-03-30T16:21:23Z</dc:date>
    </item>
    <item>
      <title>Re: Empty files on upload</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Empty-files-on-upload/m-p/509086#M25127</link>
      <description>&lt;P&gt;[Cross-linking for reference:&amp;nbsp;&lt;A href="https://stackoverflow.com/questions/66862389/image-upload-to-dropbox-api-from-ios-sends-corrupted-file-to-dropbox" target="_blank"&gt;https://stackoverflow.com/questions/66862389/image-upload-to-dropbox-api-from-ios-sends-corrupted-file-to-dropbox&lt;/A&gt;&amp;nbsp;]&lt;/P&gt;
&lt;P&gt;The&amp;nbsp;&lt;A href="https://www.dropbox.com/developers/documentation/http/documentation#files-upload" target="_self"&gt;/2/files/upload endpoint&lt;/A&gt; is a&amp;nbsp;&lt;A href="https://www.dropbox.com/developers/documentation/http/documentation#formats" target="_self"&gt;"content-upload" style&lt;/A&gt; endpoint, meaning that it requires the file data to be uploaded in the request body. I see you're attempting to set the file data as such by using the "body" parameter in your "requestOptions" that you pass to "fetch".&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That seems correct, but you'll need to make sure your "file" variable contains the actual file data you want to upload.&lt;/P&gt;
&lt;P&gt;I understand you currently just have the URL for local file data though; not the file data itself. You'll need to read the data from the local filesystem in order to pass the data along. I'm afraid I can't offer much guidance on doing so though as that's not related to the&amp;nbsp;Dropbox API itself. You may need to refer to the relevant iOS documentation from Apple (or otherwise React/Expo if they offer functionality for this).&lt;/P&gt;</description>
      <pubDate>Tue, 30 Mar 2021 17:23:11 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Empty-files-on-upload/m-p/509086#M25127</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2021-03-30T17:23:11Z</dc:date>
    </item>
    <item>
      <title>Re: Empty files on upload</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Empty-files-on-upload/m-p/509088#M25128</link>
      <description>&lt;P&gt;I was able to read the base64 data that I got back and then used that to upload.&amp;nbsp; So I am uploading a variable that has the base64 stuff and now the upload is 1.06mb but is still corrupted/not viewable.&amp;nbsp; Any idea?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;let data = result.uri.split(",")[1];

setImageData(data);&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 30 Mar 2021 17:26:25 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Empty-files-on-upload/m-p/509088#M25128</guid>
      <dc:creator>gmacerola</dc:creator>
      <dc:date>2021-03-30T17:26:25Z</dc:date>
    </item>
    <item>
      <title>Re: Empty files on upload</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Empty-files-on-upload/m-p/509089#M25129</link>
      <description>&lt;P&gt;When you upload data to&amp;nbsp;Dropbox via the API, you should upload the actual file data, without any encoding (such as base64 encoding).&amp;nbsp;Dropbox does not apply any decoding on the uploaded file data; it will just commit what you send. Try uploading the data without the base64 encoding.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Mar 2021 17:29:59 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Empty-files-on-upload/m-p/509089#M25129</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2021-03-30T17:29:59Z</dc:date>
    </item>
    <item>
      <title>Re: Empty files on upload</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Empty-files-on-upload/m-p/509171#M25131</link>
      <description>&lt;P&gt;I understand.&amp;nbsp; I just can't seem to find a way to convert the base64 data to binary in react-native.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Mar 2021 21:47:54 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Empty-files-on-upload/m-p/509171#M25131</guid>
      <dc:creator>gmacerola</dc:creator>
      <dc:date>2021-03-30T21:47:54Z</dc:date>
    </item>
  </channel>
</rss>

