【发布时间】:2021-03-21 14:48:37
【问题描述】:
我正在尝试使用端点 buckets/:bucketKey/objects/:objectName/resumable 上传文件 即使是最后一块,我也总是得到响应代码 202。根据文档,我应该收到响应 200,其中包含一些最终上传的骨灰盒详细信息。如何解决这个问题?为了测试,我使用了 17 MB 文件。但我的主要议程是上传更大的文件。 以下是我的代码:
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();
}
}
【问题讨论】:
标签: autodesk-forge autodesk-data-management