Forum Discussion

lakshmak's avatar
lakshmak
Helpful | Level 5
9 years ago
Solved

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

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'.

  • 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.
  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff
    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.

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.5,950 PostsLatest Activity: 2 hours ago
352 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!