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 Async doesn't work when uploading a file to server

Upload Async doesn't work when uploading a file to server

lakshmak
Helpful | Level 5
Go to solution

Hello ,

 

I'm trying to upload a file to dropbox using UploadAsunc method . Everything works fine in the local system. But when i tried to publish and run from the server I'm having an exception or file doesn't get uploaded into the dropbox. Without the dropbox call everything works fine . Here is the code i'm trying to call when uplaoding it. 

 

 

Try
                        Using handler As HttpClientHandler = New HttpClientHandler()
                            Using httpclient As HttpClient = New HttpClient(handler)
                                'httpclient.Timeout = TimeSpan.FromMinutes(20)
                                Dim _DropboxClient = New DropboxClient(ApiKeyDropBox, config)
                                Dim resultstring As String = UploadToDB(_DropboxClient, dropboxdir, docName, fileBytes)
                                _DropboxClient.Dispose()
                                If Not resultstring = "RanToCompletion" Then
                                    ErrorMsg &= "The following error occured: " & resultstring
                                End If
                            End Using

                        End Using
                    Catch ex2 As Dropbox.Api.AuthException
                        ErrorMsg &= "Error details: " & ex2.Message.ToString()
                    Catch ex As HttpException
                        ErrorMsg &= "Error occured saving  file to dropbox.<br /> Error Message: " & ex.InnerException.Message

                    End Try

 

 Private Function UploadToDB(_DropboxClient As DropboxClient, Directory As String, Filename As String, Content As [Byte]()) As String
        Try
            Dim result As String = "Unknown"
            Dim trycnt As String = 0
            Dim tryLimit As String = 20
            Dim respnse As Task(Of FileMetadata)
            Using _mStream = New MemoryStream(Content)
                respnse = _DropboxClient.Files.UploadAsync(Convert.ToString(Directory & Convert.ToString("/")) & Filename, WriteMode.Overwrite.Instance, body:=_mStream)
                While Not respnse.IsCompleted And trycnt < tryLimit
                    Threading.Thread.Sleep(1000)
                    trycnt += 1
                    result = respnse.Status.ToString()
                End While
                UploadToDB = result
            End Using

        Catch ex2 As Dropbox.Api.HttpException
            UploadToDB = ex2.Message.ToString()

        End Try

    End Function

Can you please say anything that I am doing worng or what is causing the problem. 

 

This is the exception thrown : The type initializer for 'Dropbox.Api.DropboxRequestHandlerOptions' threw an exception.

 

Sometimes this is the exception i get: Could not load type 'System.Security.Authentication.SslProtocols' from assembly 'System.Net.Primitives, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

2 Accepted Solutions

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution
Dropbox does use SSL/TLS for all API calls, so your system needs to be able to make SSL/TLS connections. Based on the error message, it seems something went wrong loading System.Security.Authentication.SslProtocols. That seems to be a issue with your system itself though, not Dropbox, so I'm afraid I can't offer much insight. This question may be better suited for a Microsoft support channel or forum.

View solution in original post

lakshmak
Helpful | Level 5
Go to solution
2 Replies 2

Greg-DB
Dropbox Staff
Go to solution
Dropbox does use SSL/TLS for all API calls, so your system needs to be able to make SSL/TLS connections. Based on the error message, it seems something went wrong loading System.Security.Authentication.SslProtocols. That seems to be a issue with your system itself though, not Dropbox, so I'm afraid I can't offer much insight. This question may be better suited for a Microsoft support channel or forum.

lakshmak
Helpful | Level 5
Go to solution
Thank you
Need more support?
Who's talking

Top contributors to this post

  • User avatar
    lakshmak Helpful | Level 5
  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?