use of com.aliyun.oss.model.UploadPartRequest 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.UploadPartRequest in project aliyun-oss-java-sdk by aliyun.
the class OSSClientRequestTest method testUploadPartRequest.
@SuppressWarnings("serial")
@Test
public void testUploadPartRequest() throws Exception {
String uploadId = "upload123";
final UploadPartRequest request = new UploadPartRequest();
request.setBucketName(bucketName);
request.setKey(objectKey);
request.setUploadId(uploadId);
request.setPartNumber(1);
byte[] inputBytes = uploadId.getBytes(OSSConstants.DEFAULT_CHARSET_NAME);
ByteArrayInputStream input = new ByteArrayInputStream(inputBytes);
request.setInputStream(input);
request.setPartSize(inputBytes.length);
TestAction test1 = new TestAction() {
public void run() throws Exception {
multipartOp.uploadPart(request);
}
};
executeTest(test1, HttpMethod.PUT, bucketName + "." + endpoint.getHost(), objectKey + "?partNumber=" + request.getPartNumber() + "&uploadId=" + uploadId, new HashMap<String, String>() {
{
put("Content-Length", Long.toString(request.getPartSize()));
}
});
}
Aggregations