cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

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: 

API v2 c# upload file

API v2 c# upload file

Kardo
New member | Level 2

Hi Dears,

am using asp.net core/c# i want upload folder but its not working 

 

using (var stream = new MemoryStream(File.ReadAllBytes(@"E:\a.txt")))
{
var response = client.Files.UploadAsync("/test/" + "a.txt", WriteMode.Overwrite.Instance, body: stream);
}

 

please can anyone helop me

7 Replies 7

Greg-DB
Dropbox Staff
Can you elaborate on what you mean when you say it's "not working"? What error or unexpected output do you get?

Octavio1
Explorer | Level 3

You are missing the "await"


Kardo ha escrito:

Hi Dears,

am using asp.net core/c# i want upload folder but its not working 

 

using (var stream = new MemoryStream(File.ReadAllBytes(@"E:\a.txt")))
{
var response = await client.Files.UploadAsync("/test/" + "a.txt", WriteMode.Overwrite.Instance, body: stream);
}

 

please can anyone helop me



just before client.XXXX

 

I've used similar code and it works for small size files, however it does not work for big size files (over 30MB) I got the following exception System.Threading.Tasks.TaskCanceledException still do not know why.

Greg-DB
Dropbox Staff

@Octavio1 How long does that call take before failing with TaskCanceledException? I believe TaskCanceledException should indicate a timeout on the network connection for the API call.

Octavio1
Explorer | Level 3

It takes around 100 seconds to throw the exception, Im thinking in implementing a "session" to upload the file trough several small requests besause in the future I might need to upload larger files.

 

Still do not know how to implement it.

 

http://dropbox.github.io/dropbox-sdk-dotnet/html/M_Dropbox_Api_Files_Routes_FilesUserRoutes_UploadSe...

 

Thanks for the response, hope this can help anyone with the same issue.

Greg-DB
Dropbox Staff
Thanks! It does sound like the connection is timing out then. You should generally be able to upload 30 MB in a single call, but this will depend on various factors, such as your network connection.

Using upload sessions instead is the best solution. There's an example of using it here:

https://github.com/dropbox/dropbox-sdk-dotnet/blob/9803a40b3169acf66a2d14e29af8750ebe6e3e17/dropbox-...

Octavio1
Explorer | Level 3

You are right Gregg, after some investigation I found the following link for another thread for similar issues.

 

I used it with 1024KB chunks and it is woking properly. :slight_smile:

 

https://www.dropboxforum.com/t5/API-support/Issues-about-Chunkupload/m-p/214661#M11002

 

I'll give it a try to the sample you sent and provide my experience to the comunity.

 

Thanks!  :nerd:

 

https://github.com/dropbox/dropbox-sdk-dotnet/blob/9803a40b3169acf66a2d14e29af8750ebe6e3e17/dropbox-...

Greg-DB
Dropbox Staff

By the way, while it sounds like 30 MB is too big for your case, you may want to try something bigger than 1 MB, as a bigger chunk size will generally yield better performance overall. A good size to try would be 8 MB.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    Octavio1 Explorer | Level 3
What do Dropbox user levels mean?