Search in sources :

Example 26 with CompleteMultipartUploadRequest

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());
    }
}
Also used : OSSObject(com.aliyun.oss.model.OSSObject) TestUtils.genFixedLengthInputStream(com.aliyun.oss.integrationtests.TestUtils.genFixedLengthInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) UploadPartRequest(com.aliyun.oss.model.UploadPartRequest) CompleteMultipartUploadResult(com.aliyun.oss.model.CompleteMultipartUploadResult) PartETag(com.aliyun.oss.model.PartETag) OSSException(com.aliyun.oss.OSSException) UploadPartResult(com.aliyun.oss.model.UploadPartResult) Callback(com.aliyun.oss.model.Callback) CompleteMultipartUploadRequest(com.aliyun.oss.model.CompleteMultipartUploadRequest) Test(org.junit.Test)

Example 27 with CompleteMultipartUploadRequest

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);
}
Also used : PartETag(com.aliyun.oss.model.PartETag) CompleteMultipartUploadRequest(com.aliyun.oss.model.CompleteMultipartUploadRequest)

Example 28 with 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>&quot;PART1ABCD&quot;</ETag></Part>" + "<Part><PartNumber>2</PartNumber><ETag>&quot;PART2ABCD&quot;</ETag></Part>" + "<Part><PartNumber>3</PartNumber><ETag>&quot;PART3ABCD&quot;</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);
}
Also used : PartETag(com.aliyun.oss.model.PartETag) LinkedList(java.util.LinkedList) CompleteMultipartUploadRequest(com.aliyun.oss.model.CompleteMultipartUploadRequest) Test(org.junit.Test)

Example 29 with CompleteMultipartUploadRequest

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);
}
Also used : PartETag(com.aliyun.oss.model.PartETag) CompleteMultipartUploadRequest(com.aliyun.oss.model.CompleteMultipartUploadRequest)

Aggregations

CompleteMultipartUploadRequest (com.aliyun.oss.model.CompleteMultipartUploadRequest)29 PartETag (com.aliyun.oss.model.PartETag)29 ArrayList (java.util.ArrayList)25 OSSException (com.aliyun.oss.OSSException)22 CompleteMultipartUploadResult (com.aliyun.oss.model.CompleteMultipartUploadResult)22 Test (org.junit.Test)22 InputStream (java.io.InputStream)20 TestUtils.genFixedLengthInputStream (com.aliyun.oss.integrationtests.TestUtils.genFixedLengthInputStream)19 OSSObject (com.aliyun.oss.model.OSSObject)18 UploadPartRequest (com.aliyun.oss.model.UploadPartRequest)18 UploadPartResult (com.aliyun.oss.model.UploadPartResult)18 FileInputStream (java.io.FileInputStream)10 ListPartsRequest (com.aliyun.oss.model.ListPartsRequest)9 PartListing (com.aliyun.oss.model.PartListing)9 UploadPartCopyRequest (com.aliyun.oss.model.UploadPartCopyRequest)8 UploadPartCopyResult (com.aliyun.oss.model.UploadPartCopyResult)8 InitiateMultipartUploadRequest (com.aliyun.oss.model.InitiateMultipartUploadRequest)7 InitiateMultipartUploadResult (com.aliyun.oss.model.InitiateMultipartUploadResult)7 Callback (com.aliyun.oss.model.Callback)6 File (java.io.File)6