cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
What’s new: end-to-end encryption, Replay and Dash updates. Find out more about these updates, new features and more here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

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

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

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

jay-8
Explorer | Level 3

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,

 

 

 

4 Replies 4

Здравко
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
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(...

 

 

 

Здравко
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?

Greg-DB
Dropbox Staff

@jay-8 Dropbox no longer provides error logs like that for the API. We recommend debugging issues like this locally.

 

Anyway, we can't provide support for third party platforms themselves, so I can't say what may be different about your different environments, but as Здравко said, every Dropbox API call should either return a result or raise an exception. If you're having trouble catching or handling the result/exception programmatically, I suggest stepping through with a debugger to see what is happening first.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    Здравко Legendary | Level 20
  • User avatar
    jay-8 Explorer | Level 3
What do Dropbox user levels mean?