Search code examples
c#dropboxdropbox-api

Dropbox file uploading not showing 409 error


I'm uploading file using Dropbox core API. I have written the upload code like-

RequestResult strReq = OAuthUtility.Put
                            (
                            "https://api-content.dropbox.com/1/files_put/auto/",
                            new HttpParameterCollection
                        {
                            {"access_token", "Token"},
                            {"path","/file.txt"},
                            {"overwrite", "false"}, 
                            {"autorename","false"}, 
                            {stream}
                        }
                            );

Suppose there is a existing file in root folder named file.txt and I'm again trying to upload the same name file to same folder.I have written overwrite= false and autorename=false but surprisingly there is no error status code returning in the response.Always returning the success code 200 in the response.I need to show the proper error code.


Solution

  • Two things stand out:

    1. Your URL is https://api-content.dropbox.com/1/files_put/auto/, but it should be (for this example) https://api-content.dropbox.com/1/files_put/auto/file.txt. The path parameter should be removed from the HttpParameterCollection.
    2. I'm unfamiliar with the library you're using, but are you sure that those parameters are turned into query parameters and that stream becomes the HTTP body? I.e. the resulting URL should be https://api-content.dropbox.com/1/files_put/auto/file.txt?overwrite=false&autorename=false&access_token=<TOKEN>, and then the file content should go in the body of the request. Please make sure this is what's happening.

    Please also share the body that comes back with the 200 response. It should tell you, for example, the path of the file that got written.

    Note that if you upload the exact same file content to the same path, it doesn't count as a conflict, so when looking for a 409, make sure you're uploading different content to the file.