You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.

Forum Discussion

jimbobbles's avatar
jimbobbles
Explorer | Level 3
4 months ago

Android batch upload example?

I'm looking for a full example of batch upload (using simple uploads, not chunked) using Android. I have found bits and pieces of info scattered around:

 

I'm just looking for an example which shows how all the pieces fit together (sessions, cursors, starting, appending, finishing etc) because I'm really struggling to figure it all out. Does one exist?

 

Thanks

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

    jimbobbles Here's the current link to the example of using upload sessions in the Java SDK, to replace the broken link you found: https://github.com/dropbox/dropbox-sdk-java/blob/main/examples/examples/src/main/java/com/dropbox/core/examples/upload_file/UploadFileExample.java#L57 This example shows how to use an upload session to upload one large file (and it also earlier in the code shows how to use non-upload session functionality to upload one small file). It doesn't show any of the batch functionality, but it can be useful as an introduction to the concepts of  upload sessions, cursors, etc. If you want to add the batch functionality, you could use that as a starting point. Note though that there is no "uploadBatch" method; the batch functionality only exists for upload sessions. You can use upload sessions to upload small files too though; that will still require multiple calls (to start, append, and finish). It's not possible to upload multiple different files in just one call though.

     

    There's also this example, which shows a sample of using some of the upload session batch functionality: https://github.com/dropbox/Developer-Samples/tree/master/Blog/performant_upload That happens to be written in Python, but the logic is the same, since the different SDKs use the same HTTPS API endpoints.

    • jimbobbles's avatar
      jimbobbles
      Explorer | Level 3
      Thank you very much for the pointers. I think I've nearly pieced everything together, just not sure how to finish the batch:

      After calling uploadSessionFinishBatchV2 I get an instance of UploadSessionFinishBatchResult https://dropbox.github.io/dropbox-sdk-java/api-docs/v7.0.0/com/dropbox/core/v2/files/DbxUserFilesRequests.html#uploadSessionFinishBatchV2(java.util.List)

      I'm not sure what Im supposed to do with this. Do I somehow need to use this result in combination with uploadSessionFinishBatchCheck to check whether the result is complete, or do I need to keep polling the result entries until they complete, or do I just check the result entries immediately (i.e. is uploadSessionFinishBatchV2 a sync method which only returns once the batch finishing is complete ?) It's a little unclear.

      Once I get this working I will post my code for others to use as an example for android.
      • Здравко's avatar
        Здравко
        Legendary | Level 20

        jimbobbles wrote:
        ... (i.e. is uploadSessionFinishBatchV2 a sync method which only returns once the batch finishing is complete ?) ...

        jimbobbles, You're correct - version 2 of that method (and API call accordingly) is sync method. The deprecated version 1 can be sync or async - somethin that need to be checked and traced using the check accordingly (something you don't need to consider).

        You need to check the success of all returned entries though. You can take a look here or here.

        Hope this helps.

  • Здравко's avatar
    Здравко
    Legendary | Level 20

    Hi jimbobbles,

    Batch upload is very similar to upload a big file using session upload, so you can start with some example showing single big file (more than 150MB) upload - there are such examples; select most familiar one to you. You should use such upload style for both big and small files!

    There are 2 main specifics/differences you should keep in mind:

    1. In single file upload you may select whether to finish/close session during last append (or even on start for small files) or on finishing. Most examples upload last piece of data on finishing. In batch upload you DON'T have such a choice; all upload sessions MUST BE FINISHED/CLOSED during last append (or during start for small files)! During batch finishing every passed session has to be finished/closed already.
    2. Instead of finish, finish batch has to be used of course.

    Everything else may stay the same. It's up to you whether to start with batch start or not - it's not something mandatory; all upload sessions are the same type.

    Hope this gives direction.