Need to see if your shared folder is taking up space on your dropbox 👨‍💻? Find out how to check here.

Forum Discussion

SauravAnand's avatar
SauravAnand
Explorer | Level 4
9 years ago
Solved

UploadAsync - File got corrupt after uplaod - C#

Hi,

 

I'm trying to upload photos to Dropbox account using v2.

 

FileStream fsBlobData = new FileStream(filePath, FileMode.Open, FileAccess.Read);
byte[] bytBlobdata = new byte[fsBlobData.Length];        
using (var dbx = new DropboxClient(accessToken)) 
{
      using (var stream = new MemoryStream(bytBlobdata))
      {                                  
           var response = await dbx.Files.UploadAsync("/"+ folder + "/" + 
           fileName, WriteMode.Overwrite.Instance, body: stream);                  
           return response;
       }               
}

But after uplaoding when i try to preview file it says "This file can’t be previewed".

My original file is 129kb and uploaded is 129.19kb.

 

Then i have downloaded the same file from Dropbox itself and try to open with windows image viewer but windows photo viewer can't open this picture.

 

Please tell me what i'm doing wrong here.

Thank you.

  • You appear to setting bytBlobdata to an empty array (with a size of the length of the file) and then uploading that, so the resulting file will just be zeros.

    You need to supply the actual file data instead. For example, you can just pass in fsBlobData as the body to UploadAsync instead of bytBlobdata.

2 Replies

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    9 years ago
    You appear to setting bytBlobdata to an empty array (with a size of the length of the file) and then uploading that, so the resulting file will just be zeros.

    You need to supply the actual file data instead. For example, you can just pass in fsBlobData as the body to UploadAsync instead of bytBlobdata.
  • SauravAnand's avatar
    SauravAnand
    Explorer | Level 4
    9 years ago
    Hi Greg,

    Thank you. Your solution worked, i have passed fsBlobData as body to UploadAsync and file got uploaded correctly.

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.

The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!