We’re Still Here to Help (Even Over the Holidays!) - find out more here.
Forum Discussion
solsupp
8 years agoExplorer | Level 3
Dropbox API
Have tried one of your examples for uploading larger files, getting on error on this line
updated = CType(ChunkUpload((filePath + ("/" + fileName)), fs, ChunkSize, dbx), Task(Of FileMetadata))Additional information: Unable to cast object of type 'System.Threading.Tasks.Task`1[System.Threading.Tasks.VoidTaskResult]' to type 'System.Threading.Tasks.Task`1[Dropbox.Api.Files.FileMetadata]'.
it relatesd to the function below, which is cast as a task
Private Async Function ChunkUpload(ByVal path As String, ByVal stream As FileStream, ByVal chunkSize As Integer, dbx As DropboxClient) As Task
Dim numChunks As Integer = CType(Math.Ceiling((CType(stream.Length, Double) / chunkSize)), Integer)
Dim buffer() As Byte = New Byte((chunkSize) - 1) {}
Dim sessionId As String = Nothing
Dim idx = 0
Do While (idx < numChunks)
Dim byteRead = stream.Read(buffer, 0, chunkSize)
Dim memStream = New MemoryStream(buffer, 0, byteRead)
If (idx = 0) Then
Dim result = dbx.Files.UploadSessionStartAsync(False, memStream)
sessionId = CType(result.Id, String)
Else
Dim cursor = New UploadSessionCursor(sessionId, CType((chunkSize * idx), System.UInt64))
If (idx _
= (numChunks - 1)) Then
Dim fileMetadata As FileMetadata = Await dbx.Files.UploadSessionFinishAsync(cursor, New CommitInfo(path), memStream)
Console.WriteLine(fileMetadata.PathDisplay)
Else
Await dbx.Files.UploadSessionAppendV2Async(cursor, False, memStream)
End If
End If
idx = (idx + 1)
Loop
End FunctionCan you give any advice
1 Reply
- Greg-DB8 years ago
Dropbox Community Moderator
Based on your newer thread, it sounds like you already sorted this out, so I'll follow up with you on your new question there.
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!