I am trying to batch upload multiple files via uploadSessionAppendV2, but somehow all the files are written to a single file.
Lets say i have two identical files file1.txt, file2.txt , each with size 2575.
Here is my code
List<UploadSessionFinishArg> entries = new ArrayList<>();
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());
The problem is, all the data from both files is commited to /uploads/file2.txt, and file1.txt is not created at all.
This is the response i get, correct_offset":5150 for the first file, which is confusing.
{
".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"
}]
}