Forum Discussion

Continuous I.'s avatar
Continuous I.
New member | Level 1
11 years ago

CSharp SDK await dbx.Files.UploadAsync(...) object gets disposed before upload

Hi, although I've mastered uploading text content to Dropbox, when trying to upload byte content (typical file, 18 MB), I get the error:

"ERROR: The object was used after being disposed"

The code is as follows, and the error was thrown in a try-catch in the second code block:

 

using (var dbx = new DropboxClient("My_Token"))
{
await UploadToDropBox(dbx, "/test", IPATargetFileName, fullPathToFileToUpload);
}
// the method called is in the next code block

async Task UploadToDropBox(DropboxClient dbx, string dropboxfolder, string dropboxfilename, string filepathtoUpload)
{
using (var mem = new MemoryStream(File.ReadAllBytes(filepathtoUpload)))
{
try
{
var updated = await dbx.Files.UploadAsync(
dropboxfolder + "/" + dropboxfilename,
WriteMode.Overwrite.Instance,
body: mem);
}
catch (Exception ex)
{
LogMessage(string.Format(" : ERROR: {0}", ex.Message));
}
}
}
 

I'm, guessing that this is a MemoryStream / FileStream problem but the API example only shows how to upload a text file.

Kind regards,

Anthony

 

 

21 Replies

Replies have been turned off for this discussion

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!