cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Update: Find information on Dropbox support during COVID-19 here
Close

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted

UploadAsync - File got corrupt after uplaod - C#

Explorer | Level 3

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.

1 Accepted Solution

Accepted Solutions
Highlighted

Re: UploadAsync - File got corrupt after uplaod - C#

Dropboxer
Dropboxer
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.

View solution in original post

2 Replies 2
Highlighted

Re: UploadAsync - File got corrupt after uplaod - C#

Dropboxer
Dropboxer
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.

View solution in original post

Highlighted

Re: UploadAsync - File got corrupt after uplaod - C#

Explorer | Level 3
Hi Greg,

Thank you. Your solution worked, i have passed fsBlobData as body to UploadAsync and file got uploaded correctly.
Polls
Do you know how to organize your files and folders?
We have created a guide on folder best practice, so you can get organized now check it out here.

Work Smarter with Dropbox

The way we work is changing. Share and discover new ways to work smarter with Dropbox in our community.

Sound good? Let's get started.
Who's talking

Top contributors to this post

What do Dropbox user levels mean?
Need more support?