Take Your Search Game to the Next Level with Dropbox Dash  🚀✨ Curious how it works? Ask us here! 

Forum Discussion

sbrownnw's avatar
sbrownnw
Explorer | Level 4
2 years ago
Solved

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

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?

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

6 Replies

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    2 years ago

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

  • sbrownnw's avatar
    sbrownnw
    Explorer | Level 4
    2 years ago

    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's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    2 years ago

    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's avatar
    sbrownnw
    Explorer | Level 4
    2 years ago

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

     

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    2 years ago

    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.

About Discuss Dropbox Developer & API

Node avatar for Discuss Dropbox Developer & API
Make connections with other developers810 PostsLatest Activity: 20 hours ago
256 Following

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 or Facebook.

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!