0

This is the modified code about uploadsession soo at small size file it working like a charm but when I try larger file like 5mb up. The following error keep showing up :

+$exception {"lookup_failed/closed/..."} System.Exception {Dropbox.Api.ApiException}

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

okay now its fixed, but when i got home, and try this code at my home,i got error, is this method are affected by slow internet connection ?.cause my campus have a decent speed.

this is the error message

+$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

this error window i got

A first chance exception of type 'System.ObjectDisposedException' occurred in System.dll

Additional information: Cannot access a disposed object.

1 Answers1

0

This Closed error indicates you can't continue uploading to the upload session because it's already been closed.

The UploadSessionStartAsync and UploadSessionAppendV2Async both take a bool parameter called close, which closes the session.

You're always setting that to True when you call those, closing the sessions. You shouldn't close a session until you're finished uploading data for it.

Greg
  • 16,359
  • 2
  • 34
  • 44
  • okay greg now, im facing with this eror when i got home, my home internet kind of slow, when i on my campus doing this project your code is work but now, its not. – Andru Deva Lukito Jan 19 '17 at 14:24
  • [`UploadSessionCursor`](https://dropbox.github.io/dropbox-sdk-dotnet/html/P_Dropbox_Api_Files_UploadSessionCursor_Offset.htm) keeps track of the amount uploaded. – Greg Jan 19 '17 at 15:57
  • If you're running in to a new issue, open a new post with the details. – Greg Jan 19 '17 at 15:58
  • [To The Next Question](http://stackoverflow.com/questions/41744934/dropbox-api-upload-session-error-on-slow-internet) this my question about are slow internet affect this method cause when i try on my campus its working but when i got home its not – Andru Deva Lukito Jan 19 '17 at 23:48