在服务器上发布时无法将文件上载到Dropbox

时间:2017-02-06 16:25:21

标签: vb.net dropbox-api

我正在尝试将文件上传到Dropbox。当我在本地运行时,文件上传并且代码可以正常工作。但是文件永远不会在服务器上发布时上传。我有以下错误。

无法加载类型' System.Security.Authentication.SslProtocols'来自assembly&System; Net.Primitives,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = *********'。

我尝试使用以下代码示例上传

public sub uploadtodropbox()
  Using httpclient As New HttpClient
                        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 Sub

这就是上传到Dropbox的功能

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

结束尝试 结束功能。

我试过没有使用httpclient然后我收到此错误:

Dropbox.Api.DropboxRequestHandlerOptions&#39;的类型初始值设定项。抛出异常。

谢谢

1 个答案:

答案 0 :(得分:0)

我回答。我有system.Net.primitives程序集,这会导致将文件上传到Dropbox时出现问题。我需要做的就是删除引用,并且System.Net.Http中的版本已经在web.config文件中设置了错误。一旦我在配置中设置它一切正常。

对于证书,我将on post设置回来验证并允许在事件处理程序中生成的证书。