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: 

Re: How to upload file from external dll vb project

How to upload file from external dll vb project

senthilnathan205
Explorer | Level 3

Hi sir,

      I use the Dropbox.Api dll in my own dll that i create. i use the dll in my other project to upload files in dropbox i pass token key. dropbox folder path, local file path. i use the function Files.UploadAsync(), i got exception like this "An error occurred while sending the request." and also have stack trace like this

at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Dropbox.Api.DropboxRequestHandler.<RequestJsonString>d__20.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Dropbox.Api.DropboxRequestHandler.<RequestJsonStringWithRetry>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Dropbox.Api.DropboxRequestHandler.<Dropbox-Api-Stone-ITransport-SendUploadRequestAsync>d__13`3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at AmberSoftDBPlugin.AmberSoftDB.<UploadFilesToDropBoxAsync>d__0.MoveNext() in D:\AmberSoftDBPlugin\AmberSoftDBPlugin\AmberSoftDB.cs:line 42

 

can u help how to  solve the issue above happen.

        

8 Replies 8

Greg-DB
Dropbox Staff

I'll be happy to help with any issues you're having with the Dropbox API, but I'll need some more information. Please reply with:

  • the name and version number of the platform and SDK/library you are using, if any
  • the steps to reproduce the issue, including relevant code snippet(s), but don't include any access or refresh token(s)
  • the full text of any error or unexpected output (the output you shared here doesn't seem to show the full error message from the Dropbox API/SDK)

senthilnathan205
Explorer | Level 3

hi sir,

         thanks for ur reply

 

the version i used for dropbox api 6.25  for one 

 

senthilnathan205_0-1657165449563.png

 

for two below code

 

var dpClinet = new Dropbox.Api.DropboxClient(TokenKey);
try
{
UploadArg uploadArg = new UploadArg(folder, WriteMode.Overwrite.Instance, true);
using (var mem = new MemoryStream(File.ReadAllBytes(fileToUpload)))
{
// var mem = new MemoryStream(File.ReadAllBytes(fileToUpload));
// var updated = await dpClinet.Files.UploadAsync(uploadArg, mem);
//var updated = await dpClinet.Files.UploadAsync(folder, WriteMode.Overwrite.Instance, body: mem);
FileMetadata fileMetadata = await dpClinet.Files.UploadAsync(folder, mode: WriteMode.Overwrite.Instance, autorename: false, body: mem);

}
}
catch(Exception ex)
{
DoNotify(ex.Message);
DoNotify(ex.StackTrace);
}

for three below errors

 

An error occurred while sending the request.

 

at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Dropbox.Api.DropboxRequestHandler.<RequestJsonString>d__20.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Dropbox.Api.DropboxRequestHandler.<RequestJsonStringWithRetry>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Dropbox.Api.DropboxRequestHandler.<Dropbox-Api-Stone-ITransport-SendUploadRequestAsync>d__13`3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at AmberSoftDBPlugin.AmberSoftDB.<UploadFilesToDropBoxAsync>d__0.MoveNext() in D:\AmberSoftDBPlugin\AmberSoftDBPlugin\AmberSoftDB.cs:line 42

Здравко
Legendary | Level 20

@senthilnathan205 wrote:

...

var dpClinet = new Dropbox.Api.DropboxClient(TokenKey);

...


Hi @senthilnathan205,

At the beginning, one error not directly related to the current issue, but will bring up soon, if let unfixed in advance. In your client initialization you are using access token only. This type of token is with limited validity (at most 4 hours). After that, user will need to relink your application again and again... To avoid such continuous token expiration, you have to initialize you client object with refresh token, access token expiration time, and application key (application secret might be need too depending on selected authentication type) in addition to the access token. If need, change your authentication flow.

 


@senthilnathan205 wrote:

...
FileMetadata fileMetadata = await dpClinet.Files.UploadAsync(folder, mode: WriteMode.Overwrite.Instance, autorename: false, body: mem);

...


Hm...🤔 What's the content of 'folder' passed as 'path' parameter? Take in mind that path has to point to the target file (full path) where the 'body' will be put to, not to the containing folder only! Dropbox can NOT know what's the desired file name, if not pointed explicitly. 😉

Hope this gives direction.

Greg-DB
Dropbox Staff

@senthilnathan205 I just tried this code, plugging in my own values and access token, with v6.25.0  of the library, and it ran successfully for me.

 

Is that the entirety of the error output?


Also, is there anything on your network connection, such as a proxy, firewall, VPN, anti-virus, etc., that may be interfering with your connections to content.dropboxapi.com? You may need to contact your network admin for help with that.

senthilnathan205
Explorer | Level 3

hi sir,

 

        I replace token key each 4hr 

senthilnathan205
Explorer | Level 3

Hi  @Greg-DB 

       

                   thanks for reply. I use sample project to check the code it work correctly, but i use the in form behavior in Rapid flow here only not work. 

Здравко
Legendary | Level 20

@senthilnathan205 wrote:

...

        I replace token key each 4hr 


Yes, exactly validity period (up border) for access token (as you named it "token key"). 🤷 Continue, if you like to be so. Otherwise, change you code to use refresh token too. That's it.

Greg-DB
Dropbox Staff

@senthilnathan205 Yes, as Здравко noted, if you need access for more than four hours, you should request and use a refresh token as well. For the official Dropbox API v2 .NET SDK, you can find an example of getting and using a refresh token in the OauthBasic example (non-PKCE, meant for server-side apps) as well as in the OAuthPKCE example (PKCE, meant for client-side apps)

Need more support?