use of com.aliyun.oss.model.CompleteMultipartUploadRequest in project aliyun-oss-java-sdk by aliyun.
the class CallbackTest method testMultipartUploadCallbackBodyType.
/**
* callback body type,type is json
*/
@Test
public void testMultipartUploadCallbackBodyType() {
String key = "multipart-upload-callback-body-type";
try {
String uploadId = claimUploadId(ossClient, bucketName, key);
InputStream instream = genFixedLengthInputStream(instreamLength);
List<PartETag> partETags = new ArrayList<PartETag>();
UploadPartRequest uploadPartRequest = new UploadPartRequest();
uploadPartRequest.setBucketName(bucketName);
uploadPartRequest.setKey(key);
uploadPartRequest.setInputStream(instream);
uploadPartRequest.setPartNumber(1);
uploadPartRequest.setPartSize(instreamLength);
uploadPartRequest.setUploadId(uploadId);
UploadPartResult uploadPartResult = ossClient.uploadPart(uploadPartRequest);
partETags.add(uploadPartResult.getPartETag());
Callback callback = new Callback();
callback.setCallbackUrl(callbackUrl);
callback.setCallbackHost("oss-cn-hangzhou.aliyuncs.com");
callback.setCallbackBody("{\\\"mimeType\\\":${mimeType},\\\"size\\\":${size}}");
callback.setCalbackBodyType(CalbackBodyType.JSON);
CompleteMultipartUploadRequest completeMultipartUploadRequest = new CompleteMultipartUploadRequest(bucketName, key, uploadId, partETags);
completeMultipartUploadRequest.setCallback(callback);
CompleteMultipartUploadResult completeMultipartUploadResult = ossClient.completeMultipartUpload(completeMultipartUploadRequest);
byte[] buffer = new byte[bufferLength];
int nRead = completeMultipartUploadResult.getCallbackResponseBody().read(buffer);
completeMultipartUploadResult.getCallbackResponseBody().close();
Assert.assertEquals(callbackResponse, new String(buffer, 0, nRead));
OSSObject obj = ossClient.getObject(bucketName, key);
Assert.assertEquals(key, obj.getKey());
Assert.assertEquals(instreamLength, obj.getObjectMetadata().getContentLength());
obj.close();
} catch (Exception ex) {
Assert.fail(ex.getMessage());
}
}
use of com.aliyun.oss.model.CompleteMultipartUploadRequest in project aliyun-oss-java-sdk by aliyun.
the class MultipartUploadSample method completeMultipartUpload.
private static void completeMultipartUpload(String uploadId) {
// Make part numbers in ascending order
Collections.sort(partETags, new Comparator<PartETag>() {
@Override
public int compare(PartETag p1, PartETag p2) {
return p1.getPartNumber() - p2.getPartNumber();
}
});
System.out.println("Completing to upload multiparts\n");
CompleteMultipartUploadRequest completeMultipartUploadRequest = new CompleteMultipartUploadRequest(bucketName, key, uploadId, partETags);
client.completeMultipartUpload(completeMultipartUploadRequest);
}
use of com.aliyun.oss.model.CompleteMultipartUploadRequest in project aliyun-oss-java-sdk by aliyun.
the class OSSClientRequestTest method testCompleteMultipartUploadRequest.
@Test
public void testCompleteMultipartUploadRequest() {
String uploadId = "upload123";
List<PartETag> partETags = new LinkedList<PartETag>();
partETags.add(new PartETag(2, "PART2ABCD"));
partETags.add(new PartETag(1, "PART1ABCD"));
partETags.add(new PartETag(3, "PART3ABCD"));
final CompleteMultipartUploadRequest request = new CompleteMultipartUploadRequest(bucketName, objectKey, uploadId, partETags);
String requestXml = "<CompleteMultipartUpload>" + "<Part><PartNumber>1</PartNumber><ETag>"PART1ABCD"</ETag></Part>" + "<Part><PartNumber>2</PartNumber><ETag>"PART2ABCD"</ETag></Part>" + "<Part><PartNumber>3</PartNumber><ETag>"PART3ABCD"</ETag></Part>" + "</CompleteMultipartUpload>";
TestAction test1 = new TestAction() {
public void run() throws Exception {
multipartOp.completeMultipartUpload(request);
}
};
executeTest(test1, HttpMethod.POST, bucketName + "." + endpoint.getHost(), objectKey + "?uploadId=" + uploadId, null, requestXml, -1);
}
use of com.aliyun.oss.model.CompleteMultipartUploadRequest in project aliyun-oss-java-sdk by aliyun.
the class OSSUploadOperation method complete.
private CompleteMultipartUploadResult complete(UploadCheckPoint uploadCheckPoint, UploadFileRequest uploadFileRequest) {
Collections.sort(uploadCheckPoint.partETags, new Comparator<PartETag>() {
@Override
public int compare(PartETag p1, PartETag p2) {
return p1.getPartNumber() - p2.getPartNumber();
}
});
CompleteMultipartUploadRequest completeUploadRequest = new CompleteMultipartUploadRequest(uploadFileRequest.getBucketName(), uploadFileRequest.getKey(), uploadCheckPoint.uploadID, uploadCheckPoint.partETags);
completeUploadRequest.setCallback(uploadFileRequest.getCallback());
return multipartOperation.completeMultipartUpload(completeUploadRequest);
}
Aggregations