We're making changes to the Community, so you may have received some notifications - thanks for your patience and welcome back. Learn more here.
Forum Discussion
Keith B.7
9 years agoHelpful | Level 7
-uploadSessionStartUrl: example?
Apologies for the barrage of questions - it's only because I'm updating a large class to use API 2.
Is there an example of how to use -uploadSessionStartUrl: anywhere? (A Google search brings up nothing but the documentation.) I use -uploadFileChunk: a lot in API 1, so need to replace this with -uploadSessionStartUrl: in API 2. I think I just about understand how to do this from the documentation and header files, but was hoping there was an example somewhere to check.
Thanks,
Keith
- Greg-DBDropbox Staff
I don't believe we have a good sample of that for the Objective-C SDK in particular, but I'll be sure to pass this along as a request for one.
There's a sample for the Swift SDK here, which may be useful though:
The logic should be pretty much the same.
- Keith B.7Helpful | Level 7
Great, thank you.
- Keith B.7Helpful | Level 7
I'm trying to get this to work right now, but one thing I cannot figure out is how to calculate the offset. I can't quite work it out from the Swift code - it seems that there's a set chunk size there of 5MB, but I don't know why that is. And I'm using the -uploadUrl: method rather than the -uploadData: methods that are used in both of the examples in the link.
In API 1, the -restClient:uploadedFileChunk:newOffset:fromFile:expires: delegate methods provided the next offset required. If the file's file size >= this offset, you would commit the upload, otherwise you would upload the next chunk from this offset. But in V2, I can see no way of getting this offset. After you have started an upload session, DBFILESUploadSessionStartResult does not return an offset. And the response callback for -uploadSessionAppendV2Url: has a nil object as its first parameter, so there's no way to get the offset from there, either.
From the example, it seems that the code is just assuming that Dropbox's chunking upload methods upload in chunks of 5MB and so working things out from there, but that doesn't seem to be documented, and I can't see anywhere that it's setting the chunk size. All it's telling the Dropbox frameworks is, "Here's a URL, here's the session ID, here's where we're currently at (the offset), now upload the next chunk." So it seems there's no way of knowing how much has been uploaded (and therefore what the next offset is) when you receive the callback for either -uploadSessionStartUrl: or -uploadSessionAppendV2:.
I must be missing something obvious here - how do I get the offset?
EDIT: Ah, okay, re-reading the sample code, I finally figured out that it *is* setting the chunk size itself by using data.subdataWithRange and uploading subsections of the data. So, I *think* I can see how that would work for -uploadSessionStartData: (and possibly move over to using that method). But how does it work with -uploadSessionStartUrl:?
Thanks!
Keith
- Greg-DBDropbox Staff
The 5 MB chunk size is somewhat arbitrary, and up to the app. The best size would depend on various factors. When the connection is reliable, larger chunk sizes mean better overall performance. If there are connection errors, smaller chunk sizes means you have to retransmit fewer bytes when requests do fail. You may want to try different sizes to see what works best for your app.
Anyway, for both versions of the method, the input you provide is expected to be just the data you want to upload for that single request. So for the URL version, the URL should point to just one chunk size's worth of data.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,875 PostsLatest Activity: 2 months agoIf 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!