I am trying to upload file using end point buckets/:bucketKey/objects/:objectName/resumable I am always getting the response code 202 even for the final chunk. As per documentation i should receive response 200 with some urn details for the final upload. How to solve this? For testing i was using 17 MB file. But my main agenda is to upload larger files. Below are my code:
byte[] bytes = uploadObjectRequest.getInputStream().readAllBytes();
int fileSize = bytes.length;
System.out.println("File size in bytes: "+ fileSize);
int chunkSize = 5 * 1024 * 1024 ;
int nbChunks = (fileSize / chunkSize) + 1;
try(ByteArrayInputStream isReader = new ByteArrayInputStream(bytes)){
for(int i = 0; i < nbChunks; i++){
int start = i * chunkSize;
int end = Math.min(fileSize, (i + 1) * chunkSize) - 1;
String range = "bytes " + start + "-" + end + "/" + fileSize;
// length of this piece
int contentLength = end - start + 1;
byte[] buffer = new byte[contentLength];
int count = isReader.read(buffer, 0, contentLength);
ByteArrayInputStream is = new ByteArrayInputStream(buffer);
uploadObjectRequest.setContentLength(contentLength);
uploadObjectRequest.setContentRange(range);
String sessionId = UUID.randomUUID().toString();
uploadObjectRequest.setSessionId(sessionId);
uploadObjectRequest.setInputStream(is);
System.out.println(String.format("For Chunk %s contentLength %s, contentRange %s, sessionId %s", i, contentLength, range, sessionId));
HttpResponse res = datamanagementAPI.uploadObjsInChunk(uploadObjectRequest, authenticator);
int status = res.getStatusLine().getStatusCode();
}
}
I got an example in Node.js posted here. Back to your code, you need to modify it like this:
After talking, note that sessionId should be the same for all chunk upload. Otherwise, OSS cannot combine all chunks together.