Vb.net 使用上载会话时出现Dropbox错误

Vb.net 使用上载会话时出现Dropbox错误,vb.net,dropbox,dropbox-api,Vb.net,Dropbox,Dropbox Api,这是关于小文件上传会话soo的修改代码,它工作起来很有魅力,但当我尝试像5mb这样的大文件时。以下错误将继续显示: +$exception{“lookup_failed/closed/…”}System.exception{Dropbox.Api.ApiException} Private Async Sub-UploadToolStripMenuItem2\u单击(发送方作为对象,e作为事件参数)处理UploadToolStripMenuItem2。单击 Dim C作为新的OpenFileDi

这是关于小文件上传会话soo的修改代码,它工作起来很有魅力,但当我尝试像5mb这样的大文件时。以下错误将继续显示:

+$exception{“lookup_failed/closed/…”}System.exception{Dropbox.Api.ApiException}

Private Async Sub-UploadToolStripMenuItem2\u单击(发送方作为对象,e作为事件参数)处理UploadToolStripMenuItem2。单击
Dim C作为新的OpenFileDialog
C.Title=“选择文件”
C.Filter=“所有文件(*.*)|*.”
如果C.ShowDialog=Windows.Forms.DialogResult.OK,则
Dim fileinfos=Path.GetFileName(C.FileName)
Dim filetempat=Path.GetFullPath(C.FileName)
Dim tempat As String=direktori.Text&“/”&fileinfos
等待上载(filetempat,tempat)
如果结束
端接头
异步函数上载(localPath作为字符串,remotePath作为字符串)作为任务
常量ChunkSize为整数=4096*1024
使用fileStream=File.Open(localPath,FileMode.Open)
如果fileStream.Length此错误表示无法继续上载到上载会话,因为它已关闭

和都使用名为
close
bool
参数,该参数将关闭会话


调用这些时,您总是将其设置为
True
,然后关闭会话。在完成上传数据之前,您不应该关闭会话。

好的,greg,现在我面临着这个问题。当我回到家时,我的家庭互联网有点慢,当我在校园里做这个项目时,您的代码是有效的,但现在不是。跟踪上载的数量。如果您遇到新问题,请打开一篇包含详细信息的新文章。我的问题是,网速慢会影响这种方法吗?因为当我在校园里尝试时,它是有效的,但当我回到家时,它就不起作用了
Private Async Sub UploadToolStripMenuItem2_Click(sender As Object, e As EventArgs) Handles UploadToolStripMenuItem2.Click
    Dim C As New OpenFileDialog
    C.Title = "Choose File"
    C.Filter = "All Files (*.*)|*.*"
    If C.ShowDialog = Windows.Forms.DialogResult.OK Then
        Dim fileinfos = Path.GetFileName(C.FileName)
        Dim filetempat = Path.GetFullPath(C.FileName)
        Dim tempat As String = direktori.Text & "/" & fileinfos
        Await Upload(filetempat, tempat)

    End If
End Sub
Async Function Upload(localPath As String, remotePath As String) As Task
    Const ChunkSize As Integer = 4096 * 1024
    Using fileStream = File.Open(localPath, FileMode.Open)
        If fileStream.Length <= ChunkSize Then
            Await A.Files.UploadAsync(remotePath, body:=fileStream)
        Else
            Await Me.ChunkUpload(remotePath, fileStream, ChunkSize)
        End If
    End Using
End Function

Private Async Function ChunkUpload(path As [String], stream As FileStream, chunkSize As Integer) As Task
    Dim numChunks As Integer = CInt(Math.Ceiling(CDbl(stream.Length) / chunkSize))
    Dim buffer As Byte() = New Byte(chunkSize - 1) {}
    Dim sessionId As String = Nothing
    For idx As Integer = 0 To numChunks - 1
        Dim byteRead = stream.Read(buffer, 0, chunkSize)

        Using memStream = New MemoryStream(buffer, 0, byteRead)
            If idx = 0 Then
                Dim result = Await A.Files.UploadSessionStartAsync(True, memStream)
                sessionId = result.SessionId
                kondisi.Text=byteRead
            Else
                Dim cursor = New UploadSessionCursor(sessionId, CULng(CUInt(chunkSize) * CUInt(idx)))

                If idx = numChunks - 1 Then
                    Dim fileMetadata As FileMetadata = Await A.Files.UploadSessionFinishAsync(cursor, New CommitInfo(path), memStream)
                    MessageBox.Show("Upload Complete")
                    Console.WriteLine(fileMetadata.PathDisplay)
                Else
                    Await A.Files.UploadSessionAppendV2Async(cursor, True, memStream)
                    MessageBox.Show("Upload Failed")
                End If
            End If
        End Using
    Next
End Function
+$exception {"Cannot access a disposed object.\r\nObject name: 'System.Net.Sockets.Socket'."}   System.Exception {System.ObjectDisposedException}
    this    Cannot obtain value of local or argument '<this>' as it is not available at this instruction pointer, possibly because it has been optimized away.  System.Net.Sockets.Socket

    asyncResult Cannot obtain value of local or argument 'asyncResult' as it is not available at this instruction pointer, possibly because it has been optimized away. System.IAsyncResult

    errorCode   Cannot obtain value of local or argument 'errorCode' as it is not available at this instruction pointer, possibly because it has been optimized away.   System.Net.Sockets.SocketError