We are aware of the issue with the badge emails resending to everyone, we apologise for the inconvenience - learn more here.

Forum Discussion

evry1falls's avatar
evry1falls
Collaborator | Level 8
6 years ago

VB .NET FileUpload using ChunkUpload() error lookup_failed/not_found...

I'm trying to use this code to upload a 12mb file in [Backups] folder. I converted this code from Git dotnet C# example to VB .NET code, but I get Error [File_Not_Found], when I debug this code I noticed that sessionID never returned with value either.

Await ChunkUpload("/Backups", "C:/File.png, (Int(ChunkSize)))
Private Async Function ChunkUpload(Ipath As String, chunkSize As Integer) As Task
chunkSize = 4096 * 1024 '4mb
Using stream = New MemoryStream(File.ReadAllBytes(Ipath))
Dim numChunks = Int(Math.Ceiling(stream.Length / chunkSize))
Console.WriteLine("Chunk upload file...")
Dim buffer() As Byte = New Byte(chunkSize) {}
Dim sessionId As String = String.Empty
Dim byteRead = stream.Read(buffer, 0, chunkSize)
For idx As Integer = 0 To numChunks - 1
idx += 1
Console.WriteLine("Start uploading chunk {0}", idx)
byteRead = stream.Read(buffer, 0, chunkSize)
Using memStream = New MemoryStream(buffer, 0, byteRead)
If (idx = 0) Then
Dim result = Await DBX.Files.UploadSessionStartAsync(body:=memStream)
sessionId = result.SessionIdElse
Dim Cursor As UploadSessionCursor = _
New UploadSessionCursor(sessionId, (CLng(chunkSize * idx))) If (idx = numChunks - 1) Then Await DBX.Files.UploadSessionFinishAsync(Cursor, _
New CommitInfo("/Backups" + "/" + "File.png"), memStream) Else Await DBX.Files.UploadSessionAppendV2Async(Cursor, body:=memStream) End If End If End Using Next End Using

While this code works fine with me with less large files 

Await DBX.Files.UploadAsync("/Backups" + "/" + "File.png",
                                                  WriteMode.Overwrite.Instance, True, Nothing, False, Nothing, False, memorystream)

Thank you.

  • It looks like the formatting of your code snippet has been lost, but I think the issue is that you're not actually calling 'UploadSessionStartAsync'. You immediately increment 'idx', so 'idx = 0' never returns true. I recommend adding some more logging and/or stepping through with a debugger to work out what's going on.

    For reference, there's an example of using upload sessions here, in C#, not VB, but it should still serve as a good example of the logic needed to run an upload session.

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff

    It looks like the formatting of your code snippet has been lost, but I think the issue is that you're not actually calling 'UploadSessionStartAsync'. You immediately increment 'idx', so 'idx = 0' never returns true. I recommend adding some more logging and/or stepping through with a debugger to work out what's going on.

    For reference, there's an example of using upload sessions here, in C#, not VB, but it should still serve as a good example of the logic needed to run an upload session.

    • evry1falls's avatar
      evry1falls
      Collaborator | Level 8

      Thank you that really helped a lot, I will also try the other suggestion in the other post of "overwrite"