Forum Discussion

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

Large Data Upload

Now have large data upload working, only 1 thing I cant do is share the folder.  Errors on bold text, how do I get the parent shared folder ID after upload.

 Private Async Function ChunkUpload(path As [String], stream As FileStream, chunkSize As Integer, dbx As DropboxClient) 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 = 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 dbx.Files.UploadSessionStartAsync(False, memStream)
                    sessionId = result.SessionId
                Else
                    Dim cursor = New UploadSessionCursor(sessionId, CULng(CUInt(chunkSize) * CUInt(idx)))

                    If idx = numChunks - 1 Then
                        Dim fileMetadata As FileMetadata = Await dbx.Files.UploadSessionFinishAsync(cursor, New CommitInfo(path), memStream)
                        Console.WriteLine(fileMetadata.PathDisplay)

                        Dim myIssueID As Integer = CInt(GridView1.GetRowCellValue(GridView1.FocusedRowHandle, "Issue_ID").ToString)
                        Dim myMembers() As AddMember = Nothing

                        If GridView1.SelectedRowsCount > 0 Then

                            Dim myIssueRecipientsDatatable As System.Data.DataTable
                            Dim myIssueRecipientsTableAdapter As ArchetypeDBDataSetTableAdapters.draw_issueesTableAdapter = New ArchetypeDBDataSetTableAdapters.draw_issueesTableAdapter
                            myIssueRecipientsDatatable = myIssueRecipientsTableAdapter.GetDataByIssueID(False, myIssueID)

                            If fileMetadata.SharingInfo.ParentSharedFolderId IsNot Nothing Then
                                For Each myIssuee As DataRow In myIssueRecipientsDatatable.Rows
                                    If myIssuee.Item("DREASON").ToString IsNot Nothing Then
                                        myMembers = {New AddMember(New MemberSelector.Email(myIssuee.Item("DREASON").ToString), Nothing)}
                                        Await dbx.Sharing.AddFolderMemberAsync(fileMetadata.SharingInfo.ParentSharedFolderId, myMembers, False, "A Document Issue has been created by " & fnGetCompanyName() & " as you are part of the issue distribution, this ZipFile has been made available to you.")
                                    End If
                                Next
                            End If

                        End If

                        MsgBox("Successfully Uploaded")
                    Else
                        Await dbx.Files.UploadSessionAppendV2Async(cursor, False, memStream)
                    End If
                End If
            End Using
        Next
    End Function

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

    First, to clarify when you say "Errors on bold text", do you mean you get an actual error on that 'If fileMetadata.SharingInfo.ParentSharedFolderId IsNot Nothing' line? If so, please share the full error output.

    If not, do you mean that the line just doesn't return the value you expect? In that case, what is the SharingInfo value? Note that FileMetadata.SharingInfo will only be set "if this file is contained in a shared folder".

    If a folder is not already shared, you need to share it using ShareFolder before you can add members.

    • solsupp's avatar
      solsupp
      Explorer | Level 3

      HI Sorry for not explainging.

      I am looking to get ParentSharedFolderId once the above function has completed.

      I was using and was able to get ParentSharedFolderID, 

      old Code for smaller uploads
      Dim updated As Task(Of FileMetadata) updated = dbx.Files.UploadAsync((filePath + ("/" + fileName)), WriteMode.Overwrite.Instance, body:=fs) dbx.Sharing.ShareFolderAsync(filePath, Nothing, True)

       

      but for larger data the funtion is now async and using awaits, how can I get ParentSharedFolderID, the larger function I first mentoned above returns "instance not set to an instance of an object"

      • solsupp's avatar
        solsupp
        Explorer | Level 3

        I suppose what im asking is how can I get a result from this code

         

          Private Async Function Uploadfolder(localPath As String, remotePath As String, dbx As DropboxClient, filepath As String) As Task
                Const ChunkSize As Integer = 4096 * 1024
        
        
                Using FileStream = File.Open(localPath, FileMode.Open, FileAccess.Read)
                    If FileStream.Length <= ChunkSize Then
                        Await dbx.Files.UploadAsync(remotePath, WriteMode.Overwrite.Instance, body:=FileStream)
                    Else
                        Await ChunkUpload(remotePath, FileStream, ChunkSize, dbx, filepath)
                    End If
        
                End Using
            End Function

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.5,941 PostsLatest Activity: 22 hours 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!