Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
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
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.
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"
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
When you say the error was "instance not set to an instance of an object", did you actually mean "Object instance not set to an instance of an object"? (I.e., did you accidentally drop the first word from the error?)
If so, that would seem to indicate that you have a null reference. If it's coming from the line you indicated earlier, it's probably because fileMetadata or fileMetadata.SharingInfo is null. Note that FileMetadata.SharingInfo will only be set "if this file is contained in a shared folder". Make sure you check the variable before trying to access one that may be null.
If the folder you want to share is not yet shared, you can share it using ShareFolderAsync.
Anyway, UploadAsync and UploadSessionFinishAsync have the same return type (Task<FileMetadata>) so you can use them the same way. I can't provide help with Visual Basic itself, and exactly how you choose to pass data around your methods in your code is up to you of course.
Seems to be this line that returns the NULL
Dim fileMetadata As FileMetadata = Await dbx.Files.UploadSessionFinishAsync(cursor, New CommitInfo(path), memStream)
Is there any other way I can check this file has been uploaded to the shared folder in order to add folder members.
I pass the filemetadata to : in order to add folder members, this works with smaller upload, but fails with larger
dbx.Sharing.AddFolderMemberAsync(metadata.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.")
What do you mean when you say it "seems to be this line that returns the NULL"? The UploadSessionFinishAsync method either returns Task<FileMetadata>, or raises an exception. Please add extra logging or use a debugger to confirm what is actually being returned or raised.
Anyway, UploadSessionFinishAsync is the correct way to commit and then receive the metadata for a large file upload.
Please note that SharingInfo is not guaranteed to be set. It is only set if the file is in a shared folder. You should check metadata.SharingInfo before trying to use metadata.SharingInfo.ParentSharedFolderId. More logging or a debugger would likely be helpful here as well.
Different files can be located in different folders, so it's possible one happens to be in a shared folder, and one isn't.
If you uploaded the file to a folder that is not yet shared, you can share ithe folder using ShareFolderAsync first.
Have also tried that which works, just cant get parentshartedfolderID from this task.
Dim updated As Task(Of ShareFolderLaunch) updated = dbx.Sharing.ShareFolderAsync(filePath, Nothing, True)
Once the folder is shared, I just want to add folder members.
In this latest snippet of code, I see you're using ShareFolderAsync. Since that call is to share a folder itself, it doesn't have ParentSharedFolderId like files in shared folders do.
ShareFolderAsync returns Task<ShareFolderLaunch>. You should use CheckShareJobStatusAsync to check the status after calling ShareFolderAsync. CheckShareJobStatusAsync returns Task<ShareFolderJobStatus>. If ShareFolderJobStatus.IsComplete, you can use ShareFolderJobStatus.AsComplete to get the SharedFolderMetadata.SharedFolderId.
OK, getting a bit further now, what if I already have a shared folder that exists, I get the exception "bad_path/already_shared", can I check if a folder share already exists?
Hi there!
If you need more help you can view your support options (expected response time for a 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!