Forum Discussion

solsupp's avatar
solsupp
Explorer | Level 3
7 years ago

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 Function

Can you give any advice

 

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.5,947 PostsLatest Activity: 12 minutes ago
351 Following

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 or Facebook.

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!