You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.

Forum Discussion

jay-8's avatar
jay-8
Explorer | Level 3
9 months ago

Upload fails when initiated from a C# webAPI (only)

I am able to upload files all day long using the following code, so I know it works.

 

 

 

  try
                {
                    var uploaded = await dbx.Files.UploadAsync(
                    folder + "/" + fileName,
                    //.WriteMode.Overwrite.Instance,
                    body: mem);

                    sharedLinkArg = new Dropbox.Api.Sharing.CreateSharedLinkArg(folder + "/" + fileName);
                    var link = await dbx.Sharing.CreateSharedLinkAsync(sharedLinkArg);

                    sharedLink = link.Url;
                }
                catch (AggregateException ex)
                {
                    SessionHelper.LogErrors("attachhelpers", ex.ToString(), "UploadFile", "system");
                    return sharedLink;
                }

 

 

 

 

However, if I call it from a webAPI, it fails silently. This means it won't work from our mobile app, which uses the webAPI. It's working for website users.

 

I can't catch any errors using 'catch (AggregateException ex).' I have been trying different ways of calling it all day long (async/await, task/task.Result).

 

I have tried different ways to log errors. I know logging from an async method has issues, so what works?

 

From my logging that does work, everything seems to be fine all the way up until that Try/Catch block, then it fails with no way of knowing what happened. Nothing ever worked locally, so I'm trying to debug from a live server, which doesn't help.

 

Searching, it looks like there used to be error logs on the Dropbox side. I am not able to locate these anywhere.

 

Does anyone have any tidbit here that might point me in the right direction? What's different about the webAPI than if a user is on the website pressing a button?

 

Failing that, anyone want to suggest a better way for me to catch errors from that Try/Catch block. I'm getting nothing.

 

Thanks,

 

 

 

  • Здравко's avatar
    Здравко
    Legendary | Level 20

    jay-8 wrote:

    ...

    I can't catch any errors using 'catch (AggregateException ex).' ...


    Hi jay-8,

    Did you try catching Dropbox.Api.DropboxException or some its derivative exception? 🧐 😉

    Hope this helps.

    • jay-8's avatar
      jay-8
      Explorer | Level 3

      No. Are there any examples of that anywhere?

      Is this still a thing??? It would be helpful. Can't find anything like this now:

      https://dropbox.tech/developers/debug-your-dropbox-app-with-app-error-logs

       

      I did finally get something to work. The working code on a web form could start out as a void or async void and worked (The onclick event on a web form can't return anything, so it has to be a void). However, pretty much the same code on a webAPI would not work. I had to make the webAPI async and return a task. Then I had to await the call to the dropbox code. This actually got a file from the server into Dropbox.

       

      Part of the deal here is that I don't need to actually return anything in this. Since it worked when a user was pressing a button, it seemed like it should work when called from the webAPI. That apparently wasn't the case.

       

      And that was compounded by not getting any errors anywhere in the process. Everything seemed to work all the way up to the await dbx.Files.UploadAsync(...

       

       

       

      • Здравко's avatar
        Здравко
        Legendary | Level 20

        jay-8 wrote:

        No. ...


        However you want... but try it. 🤷 It wouldn't bit you. 😁

         

        jay-8 wrote:

        ... Can't find anything like this now:

        https://dropbox.tech/developers/debug-your-dropbox-app-with-app-error-logs

        ...


        As far as I know such features are dropped and no more supported.

         


        jay-8 wrote:

        ... Everything seemed to work all the way up to the await dbx.Files.UploadAsync(...


        Did you try dump 'uploaded' variable's content?! 🤔 If there is any error, it would be there (or if no error - uploaded file metadata). Something else: Keep in mind that if no WriteMode set and when you try upload to existing file (i.e. try overwrite) - this is error! Do you do such thing?

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

5,888 PostsLatest Activity: 7 hours ago
326 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!