Cut the Clutter: Test Ignore Files Feature - sign up to become a beta tester here.

Forum Discussion

skaros's avatar
skaros
Helpful | Level 6
9 years ago

mulitple files upload doesnt work

I am using the java sdk to upload files on dropbox. Since i want to upload a bunch of them, i tried the chunck upload method. This is what i got.

 

   public MultipleUpload addFile(File file,String path) throws DbxApiException, DbxException, IOException {         
            in = new FileInputStream(file);
            sessionId = client.files().uploadSessionStart(false).uploadAndFinish(in).getSessionId();
            
            offset = file.length();
            cursor = new UploadSessionCursor(sessionId, offset);
            int index =file.getAbsolutePath().indexOf(path);
            commitInfo = new CommitInfo(path, WriteMode.OVERWRITE, false, new Date(), false);
        
            UploadSessionFinishArg arg = new UploadSessionFinishArg(cursor, commitInfo);
             
            entries.add(arg);
            return this;
        }
     
        public void commit() throws DbxException, InterruptedException {
           int count=0;
           LaunchEmptyResult result = client.files().uploadSessionFinishBatch(entries);
           while (count<10){
                    
            try { if(!client.files().uploadSessionFinishBatchCheck(result.getAsyncJobIdValue()).isInProgress()) {
                //all ok
                System.out.println("(((END"+new Date());
                return;
            }
            System.out.println("Try Again");
            Thread.sleep(5000);                
                        
        } catch (DbxException  e){
            e.printStackTrace();
         } catch (InterruptedException e) {
            e.printStackTrace();
         }
      }   
   }
    

and in order to use it i call

addFile(new File("localfile.xxx"), "/testing/builderTest/bw.tmp")
.addFile(new File("localfile.xxx"), "/testing/builderTest/aw.tmp")
.commit();

But this is not uploading anything, and it doesnt return any error either.

any help is highly appreciated.

4 Replies

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    9 years ago
    You should certainly be getting some error or output. Have you stepped through it with a debugger to see what it's doing and what code path it's taking?
  • skaros's avatar
    skaros
    Helpful | Level 6
    9 years ago

    I am not getting any error at all. Everything seems to be working as it should.

    I  print out the

    UploadSessionFinishArg.toStringMultiline() and got this

    {
      "cursor" : {
        "session_id" : "AAAAAAADdQAca70DFR87FA",
        "offset" : 160622
      },
      "commit" : {
        "path" : "/khmdhsData/testing/builderTest/aw.tmp",
        "mode" : "overwrite",
        "autorename" : false,
        "client_modified" : "2017-03-02T08:15:39Z",
        "mute" : false
      }
    }

     

    So it seems to be working. But nothing is uploaded! How can i check the state of the uploading. have no idea how to debug this

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    9 years ago
    The UploadSessionFinishArg object is just an argument that you constructed. That is, it only is a way for you to specify parameter, but doesn't itself make the API call.

    The actual API calls are to finish and check these are uploadSessionFinishBatch and uploadSessionFinishBatchCheck. What are those returning for you?
  • skaros's avatar
    skaros
    Helpful | Level 6
    9 years ago

    It seemed that the problem was on this line

    sessionId = client.files().uploadSessionStart(false).uploadAndFinish(in).getSessionId();

    from the

    public MultipleUpload addFile()

    changed it to this

    sessionId = client.files().uploadSessionStart(true).uploadAndFinish(in).getSessionId();

    and it seems to be working (so far at least)

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.6,039 PostsLatest Activity: 6 hours ago
415 Following

The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.

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!