<?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: Cannot upload Image file with Dropbox API in C# - uploading corrupt image instead in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Cannot-upload-Image-file-with-Dropbox-API-in-C-uploading-corrupt/m-p/344491#M19890</link>
    <description>&lt;P&gt;If you want to upload a local file, you can just do something like this:&lt;/P&gt;
&lt;PRE&gt;using (var file = new FileStream(srcFile, FileMode.Open))
{
    var updated = await dbx.Files.UploadAsync(
        targetFolder + "/" + targetFileName,
        WriteMode.Overwrite.Instance,
        body: file);
}&lt;/PRE&gt;
&lt;P&gt;You'll probably want to add some checking/exception handling to make sure the local file actually exists at that path though.&lt;/P&gt;</description>
    <pubDate>Tue, 14 May 2019 19:42:37 GMT</pubDate>
    <dc:creator>Greg-DB</dc:creator>
    <dc:date>2019-05-14T19:42:37Z</dc:date>
    <item>
      <title>Cannot upload Image file with Dropbox API in C# - uploading corrupt image instead</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Cannot-upload-Image-file-with-Dropbox-API-in-C-uploading-corrupt/m-p/344470#M19889</link>
      <description>&lt;P&gt;Hello.&lt;/P&gt;&lt;P&gt;I am trying to upload an image file into my dropbox account with the dropbox api. The image is being uploaded using this code, but it's a corrupt image.&lt;/P&gt;&lt;P&gt;Here is my code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;        public async Task UploadToDropbox()
        {
            using (var dbx = new DropboxClient(dbToken))
            {
                string srcFilePath = @"~\useruploads\";
                string srcFileName = "image1.png";
                string srcFile = srcFilePath + srcFileName;
                string targetFolder = "/uploads";
                string targetFileName = "userupload_" + DateTime.Now.ToString("yymmssfff") + ".png";
                                
                
                //byte[] readContent = Encoding.UTF8.GetBytes(srcFile); //uploading corrupt file
                //byte[] readContent = UTF8Encoding.UTF8.GetBytes(srcFile); //uploading corrupt file
                //var readContent = System.IO.File.ReadAllBytes(srcFile); //uploading nothing
                //byte[] readContent = System.IO.File.ReadAllBytes(srcFile); //uploading nothing
&lt;BR /&gt;                using (var mem = new MemoryStream(readContent))
                {
                    var updated = await dbx.Files.UploadAsync(
                        targetFolder + "/" + targetFileName,
                        WriteMode.Overwrite.Instance,
                        body: mem);
                }
            }
        }&lt;/PRE&gt;&lt;P&gt;Thank you for any help.&lt;/P&gt;</description>
      <pubDate>Wed, 29 May 2019 09:06:29 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Cannot-upload-Image-file-with-Dropbox-API-in-C-uploading-corrupt/m-p/344470#M19889</guid>
      <dc:creator>jimkirk</dc:creator>
      <dc:date>2019-05-29T09:06:29Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot upload Image file with Dropbox API in C# - uploading corrupt image instead</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Cannot-upload-Image-file-with-Dropbox-API-in-C-uploading-corrupt/m-p/344491#M19890</link>
      <description>&lt;P&gt;If you want to upload a local file, you can just do something like this:&lt;/P&gt;
&lt;PRE&gt;using (var file = new FileStream(srcFile, FileMode.Open))
{
    var updated = await dbx.Files.UploadAsync(
        targetFolder + "/" + targetFileName,
        WriteMode.Overwrite.Instance,
        body: file);
}&lt;/PRE&gt;
&lt;P&gt;You'll probably want to add some checking/exception handling to make sure the local file actually exists at that path though.&lt;/P&gt;</description>
      <pubDate>Tue, 14 May 2019 19:42:37 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Cannot-upload-Image-file-with-Dropbox-API-in-C-uploading-corrupt/m-p/344491#M19890</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2019-05-14T19:42:37Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot upload Image file with Dropbox API in C# - uploading corrupt image instead</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Cannot-upload-Image-file-with-Dropbox-API-in-C-uploading-corrupt/m-p/344517#M19892</link>
      <description>&lt;P&gt;Unfortunately, with that change, the program isn't going into the using bracket. I tried it out with a try/finally and it seems to just go back to the main method after the "var file = new FileStream(srcFile, FileMode.Open)" line. Any idea why that's happening?&lt;/P&gt;&lt;P&gt;Edit: This was happening because the route was incorrect - your reply worked, thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 15 May 2019 14:25:13 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Cannot-upload-Image-file-with-Dropbox-API-in-C-uploading-corrupt/m-p/344517#M19892</guid>
      <dc:creator>jimkirk</dc:creator>
      <dc:date>2019-05-15T14:25:13Z</dc:date>
    </item>
  </channel>
</rss>

