<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Java Batch upload via uploadSessionAppendV2 in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Java-Batch-upload-via-uploadSessionAppendV2/m-p/202047#M9582</link>
    <description>&lt;P&gt;Cant figure it out how to delete the post, so i ll just post the answer about how to upload files in parallel.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;UploadSessionCursor cursor = null;

for (int i = 1; i &amp;lt;= 100; i++) {
    try {

        file = localFiles.get(i);
        remoteFileName = remoteFilePath + "/" + file.getName();

        currentPath = file.getAbsolutePath();
        try (InputStream in = new FileInputStream(currentPath)) {
            sessionId = getCleint().files().uploadSessionStart(true).uploadAndFinish(in).getSessionId();

            offset = file.length();
            cursor = new UploadSessionCursor(sessionId, offset);
            System.out.println("uploaded " + currentPath + " offset" + offset);

            CommitInfo commitInfo = new CommitInfo(remoteFileName, WriteMode.OVERWRITE, false, new Date(), false);
            UploadSessionFinishArg arg = new UploadSessionFinishArg(cursor, commitInfo);
            entries.add(arg);
        } catch (Exception e) {
            e.printStackTrace();
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
}

try {

    System.out.println("Batch entries commit");

    LaunchEmptyResult result = getCleint().files().uploadSessionFinishBatch(entries);

    while (getCleint().files().uploadSessionFinishBatchCheck(result.getAsyncJobIdValue()).isInProgress()) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    UploadSessionFinishBatchJobStatus status = getCleint().files().uploadSessionFinishBatchCheck(result.getAsyncJobIdValue());
    System.out.println(status.toString());

} catch (Exception e) {
    e.printStackTrace();
}&lt;/PRE&gt;
&lt;P class="p1"&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 14 Jan 2017 00:54:38 GMT</pubDate>
    <dc:creator>abhishek9851</dc:creator>
    <dc:date>2017-01-14T00:54:38Z</dc:date>
    <item>
      <title>Java Batch upload via uploadSessionAppendV2</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Java-Batch-upload-via-uploadSessionAppendV2/m-p/202039#M9578</link>
      <description>&lt;P&gt;I am trying to batch upload multiple files via&amp;nbsp;uploadSessionAppendV2, but somehow all the files are written to a single file.&lt;/P&gt;
&lt;P&gt;Lets say i have two&amp;nbsp;identical files file1.txt, file2.txt , each with size&amp;nbsp;2575.&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="s1"&gt;Here is my code&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;List&amp;lt;UploadSessionFinishArg&amp;gt; entries = new ArrayList&amp;lt;&amp;gt;();
String sessionId = null;
long offset = 0;

// upload and get session id for first file
File file = new File("file1.txt");
InputStream in = new FileInputStream("file1.txt");
String sessionId =  getCleint().files().uploadSessionStart().uploadAndFinish(in).getSessionId();
offset =  file.length(); // 2575
UploadSessionCursor cursor = new UploadSessionCursor(sessionId,  offset);
CommitInfo commitInfo = new CommitInfo("/uploads/file1.txt", WriteMode.OVERWRITE, false, new Date(), false);
UploadSessionFinishArg arg = new UploadSessionFinishArg(cursor, commitInfo);

// second file
file = new File("file1.txt");
try (InputStream in = new FileInputStream("file2.txt")) {
    boolean close = true;
    getCleint().files().uploadSessionAppendV2(cursor, close).uploadAndFinish(in);
    offset += file.length(); //5150
    cursor = new UploadSessionCursor(sessionId,  offset);

    CommitInfo commitInfo = new CommitInfo("/uploads/file2.txt", WriteMode.OVERWRITE, false, new Date(), false);
    UploadSessionFinishArg arg = new UploadSessionFinishArg(cursor, commitInfo);
    entries.add(arg);

} catch (Exception e) {
    e.printStackTrace();
}


//now batch commit 
LaunchEmptyResult result = getCleint().files().uploadSessionFinishBatch(entries);

while ( getCleint().files().uploadSessionFinishBatchCheck(result.getAsyncJobIdValue()).isInProgress()) {
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

UploadSessionFinishBatchJobStatus status = getCleint(). files().uploadSessionFinishBatchCheck(result.getAsyncJobIdValue());
System.out.println(status.toString());&lt;/PRE&gt;
&lt;P class="p1"&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P class="p2"&gt;The problem is, all the data from both files is commited to&amp;nbsp;&lt;SPAN&gt;/uploads/file2.txt, and file1.txt is not created at all.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class="p2"&gt;&lt;SPAN&gt;This is the response i get,&amp;nbsp;&lt;SPAN&gt;correct_offset":5150 for the first file, which is confusing.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;{
    ".tag": "complete",
    "entries": [{
        ".tag": "failure",
        "failure": {
            ".tag": "lookup_failed",
            "lookup_failed": {
                ".tag": "incorrect_offset",
                "correct_offset": 5150
            }
        }
    }, {
        ".tag": "success",
        ".tag": "file",
        "name": "file2.txt",
        "id": "id:amNxvd7HFlAAAAAAAAAAvA",
        "client_modified": "2017-01-13T23:56:11Z",
        "server_modified": "2017-01-13T23:56:11Z",
        "rev": "1695120345e",
        "size": 5150,
        "path_lower": "/uploads/file2.txt",
        "path_display": "/uploads/file2.txt"
    }]
}&lt;/PRE&gt;</description>
      <pubDate>Wed, 29 May 2019 09:26:48 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Java-Batch-upload-via-uploadSessionAppendV2/m-p/202039#M9578</guid>
      <dc:creator>abhishek9851</dc:creator>
      <dc:date>2019-05-29T09:26:48Z</dc:date>
    </item>
    <item>
      <title>Re: Java Batch upload via uploadSessionAppendV2</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Java-Batch-upload-via-uploadSessionAppendV2/m-p/202047#M9582</link>
      <description>&lt;P&gt;Cant figure it out how to delete the post, so i ll just post the answer about how to upload files in parallel.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;UploadSessionCursor cursor = null;

for (int i = 1; i &amp;lt;= 100; i++) {
    try {

        file = localFiles.get(i);
        remoteFileName = remoteFilePath + "/" + file.getName();

        currentPath = file.getAbsolutePath();
        try (InputStream in = new FileInputStream(currentPath)) {
            sessionId = getCleint().files().uploadSessionStart(true).uploadAndFinish(in).getSessionId();

            offset = file.length();
            cursor = new UploadSessionCursor(sessionId, offset);
            System.out.println("uploaded " + currentPath + " offset" + offset);

            CommitInfo commitInfo = new CommitInfo(remoteFileName, WriteMode.OVERWRITE, false, new Date(), false);
            UploadSessionFinishArg arg = new UploadSessionFinishArg(cursor, commitInfo);
            entries.add(arg);
        } catch (Exception e) {
            e.printStackTrace();
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
}

try {

    System.out.println("Batch entries commit");

    LaunchEmptyResult result = getCleint().files().uploadSessionFinishBatch(entries);

    while (getCleint().files().uploadSessionFinishBatchCheck(result.getAsyncJobIdValue()).isInProgress()) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    UploadSessionFinishBatchJobStatus status = getCleint().files().uploadSessionFinishBatchCheck(result.getAsyncJobIdValue());
    System.out.println(status.toString());

} catch (Exception e) {
    e.printStackTrace();
}&lt;/PRE&gt;
&lt;P class="p1"&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 14 Jan 2017 00:54:38 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Java-Batch-upload-via-uploadSessionAppendV2/m-p/202047#M9582</guid>
      <dc:creator>abhishek9851</dc:creator>
      <dc:date>2017-01-14T00:54:38Z</dc:date>
    </item>
    <item>
      <title>Re: Java Batch upload via uploadSessionAppendV2</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Java-Batch-upload-via-uploadSessionAppendV2/m-p/202048#M9583</link>
      <description>It looks like you're only calling uploadSessionStart once. You'll need to call that once per file. That is, a single "upload session" is used to upload a single file. You can use uploadSessionFinishBatch to finish multiple different upload sessions at once though.</description>
      <pubDate>Sat, 14 Jan 2017 00:56:15 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Java-Batch-upload-via-uploadSessionAppendV2/m-p/202048#M9583</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2017-01-14T00:56:15Z</dc:date>
    </item>
    <item>
      <title>Re: Java Batch upload via uploadSessionAppendV2</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Java-Batch-upload-via-uploadSessionAppendV2/m-p/202050#M9584</link>
      <description>&lt;P&gt;Yes, I figured it out after reading&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.dropbox.com/developers/reference/data-ingress-guide" target="_blank"&gt;https://www.dropbox.com/developers/reference/data-ingress-guide&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 14 Jan 2017 00:58:42 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Java-Batch-upload-via-uploadSessionAppendV2/m-p/202050#M9584</guid>
      <dc:creator>abhishek9851</dc:creator>
      <dc:date>2017-01-14T00:58:42Z</dc:date>
    </item>
  </channel>
</rss>

