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.

Discuss Dropbox Developer & API

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

Uploading an update to a file with WriteMode.AsOverwrite mode with Id or Path fails

Uploading an update to a file with WriteMode.AsOverwrite mode with Id or Path fails

sbrownnw
Explorer | Level 4
Go to solution

Hello.  I am using the .Net Dropbox.Api (6.37.0) with the following code sample:

 

 

using Dropbox.Api;
using Dropbox.Api.Files;
using System.Text;

namespace Dropbox
{
   internal class Program
   {
      static void Main(string[] args)
      {
         DropboxClientConfig config = new DropboxClientConfig
         {
            MaxRetriesOnError = 0
         };
         DropboxClient dropboxClient = new DropboxClient(AccessToken.ValidToken, config);

         Stream stream = new MemoryStream(Encoding.UTF8.GetBytes($"this is a test"));
         UploadArg uploadArg = new UploadArg($"/foo{Guid.NewGuid()}.txt"); // upload new file to root
         var result = dropboxClient.Files.UploadAsync(uploadArg, stream).Result;

         stream = new MemoryStream(Encoding.UTF8.GetBytes($"this is an updated test"));
         result = dropboxClient.Files.UploadAsync(result.Id, mode: new WriteMode().AsOverwrite, body: stream).Result;
      }
   }
}

 

 

 When running, the second UploadAsync throws an path/conflict/file exception.  This also repros if I change the first parameter in the second UploadAsync to result.PathLower.

 

Why is this?

1 Accepted Solution

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution

Please use Dropbox.Api.Files.WriteMode.Overwrite.Instance to set the overwrite mode (instead of AsOverwrite).

View solution in original post

6 Replies 6

Greg-DB
Dropbox Staff
Go to solution

Please use Dropbox.Api.Files.WriteMode.Overwrite.Instance to set the overwrite mode (instead of AsOverwrite).

sbrownnw
Explorer | Level 4
Go to solution

Ok.  Strange, but ok.

 

I tried the similar code and it does not compile with:     mode: WriteMode.Update.Instance
And it throws the same exception with:     mode: new WriteMode().Update

 

What do I use for Updating a file?

Greg-DB
Dropbox Staff
Go to solution

For the update write mode, you need to supply the rev value that you are intending to update, so you would make that like: new WriteMode.Update(result.Rev)

sbrownnw
Explorer | Level 4
Go to solution

Thanks

 

sbrownnw
Explorer | Level 4
Go to solution

I still get a compilation error following your example (FileMetadata.Rev is a string):

sbrownnw_0-1684969863519.png

 

Greg-DB
Dropbox Staff
Go to solution

That error is occurring because you're missing the "new" necessary to create that instance. Please add the "new" back like in my message and try again.

Need more support?
Who's talking

Top contributors to this post

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