We’re Still Here to Help (Even Over the Holidays!) - find out more here.
Forum Discussion
lakshmak
9 years agoHelpful | Level 5
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 FunctionCan 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.
- Thank you
2 Replies
- Greg-DB9 years ago
Dropbox Community Moderator
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. - lakshmak9 years agoHelpful | Level 5Thank you
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
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, Facebook or Instagram.
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!