Search in sources :

Example 1 with MultipartUpload

use of com.qcloud.cos.model.MultipartUpload in project cos-java-sdk-v5 by tencentyun.

the class MultipartUploadTest method testListMultipartUploads.

@Test
public void testListMultipartUploads() {
    if (!judgeUserInfoValid()) {
        return;
    }
    String key = "ut/testListMultipart.txt";
    String uploadId = testInitMultipart(key);
    ListMultipartUploadsRequest listMultipartUploadsRequest = new ListMultipartUploadsRequest(bucket);
    listMultipartUploadsRequest.setMaxUploads(100);
    listMultipartUploadsRequest.setPrefix("ut/");
    while (true) {
        MultipartUploadListing multipartUploadListing = cosclient.listMultipartUploads(listMultipartUploadsRequest);
        List<MultipartUpload> multipartUploads = multipartUploadListing.getMultipartUploads();
        for (MultipartUpload mUpload : multipartUploads) {
            if (mUpload.getUploadId().equals(uploadId)) {
                assertEquals(key, mUpload.getKey());
                return;
            }
        }
        if (!multipartUploadListing.isTruncated()) {
            break;
        }
        listMultipartUploadsRequest.setKeyMarker(multipartUploadListing.getNextKeyMarker());
        listMultipartUploadsRequest.setUploadIdMarker(multipartUploadListing.getNextUploadIdMarker());
    }
}
Also used : MultipartUploadListing(com.qcloud.cos.model.MultipartUploadListing) MultipartUpload(com.qcloud.cos.model.MultipartUpload) ListMultipartUploadsRequest(com.qcloud.cos.model.ListMultipartUploadsRequest) Test(org.junit.Test)

Example 2 with MultipartUpload

use of com.qcloud.cos.model.MultipartUpload in project cos-java-sdk-v5 by tencentyun.

the class TransferManager method abortMultipartUploads.

/**
 * <p>
 * Aborts any multipart uploads that were initiated before the specified date.
 * </p>
 * <p>
 * This method is useful for cleaning up any interrupted multipart uploads.
 * <code>TransferManager</code> attempts to abort any failed uploads, but in some cases this may
 * not be possible, such as if network connectivity is completely lost.
 * </p>
 *
 * @param bucketName The name of the bucket containing the multipart uploads to abort.
 * @param date The date indicating which multipart uploads should be aborted.
 */
public void abortMultipartUploads(String bucketName, Date date) throws CosServiceException, CosClientException {
    MultipartUploadListing uploadListing = cos.listMultipartUploads(appendSingleObjectUserAgent(new ListMultipartUploadsRequest(bucketName)));
    do {
        for (MultipartUpload upload : uploadListing.getMultipartUploads()) {
            if (upload.getInitiated().compareTo(date) < 0) {
                cos.abortMultipartUpload(appendSingleObjectUserAgent(new AbortMultipartUploadRequest(bucketName, upload.getKey(), upload.getUploadId())));
            }
        }
        ListMultipartUploadsRequest request = new ListMultipartUploadsRequest(bucketName).withUploadIdMarker(uploadListing.getNextUploadIdMarker()).withKeyMarker(uploadListing.getNextKeyMarker());
        uploadListing = cos.listMultipartUploads(appendSingleObjectUserAgent(request));
    } while (uploadListing.isTruncated());
}
Also used : MultipartUploadListing(com.qcloud.cos.model.MultipartUploadListing) AbortMultipartUploadRequest(com.qcloud.cos.model.AbortMultipartUploadRequest) MultipartUpload(com.qcloud.cos.model.MultipartUpload) ListMultipartUploadsRequest(com.qcloud.cos.model.ListMultipartUploadsRequest)

Example 3 with MultipartUpload

use of com.qcloud.cos.model.MultipartUpload in project cos-java-sdk-v5 by tencentyun.

the class AbstractCOSClientTest method abortAllNotFinishedMultipartUpload.

private static void abortAllNotFinishedMultipartUpload() throws Exception {
    ListMultipartUploadsRequest listMultipartUploadsRequest = new ListMultipartUploadsRequest(bucket);
    MultipartUploadListing multipartUploadListing = null;
    while (true) {
        multipartUploadListing = cosclient.listMultipartUploads(listMultipartUploadsRequest);
        List<MultipartUpload> multipartUploads = multipartUploadListing.getMultipartUploads();
        for (MultipartUpload mUpload : multipartUploads) {
            String key = mUpload.getKey();
            String uploadId = mUpload.getUploadId();
            cosclient.abortMultipartUpload(new AbortMultipartUploadRequest(bucket, key, uploadId));
        }
        if (!multipartUploadListing.isTruncated()) {
            break;
        }
        listMultipartUploadsRequest.setKeyMarker(multipartUploadListing.getNextKeyMarker());
        listMultipartUploadsRequest.setUploadIdMarker(multipartUploadListing.getNextUploadIdMarker());
    }
}
Also used : MultipartUploadListing(com.qcloud.cos.model.MultipartUploadListing) AbortMultipartUploadRequest(com.qcloud.cos.model.AbortMultipartUploadRequest) MultipartUpload(com.qcloud.cos.model.MultipartUpload) ListMultipartUploadsRequest(com.qcloud.cos.model.ListMultipartUploadsRequest)

Aggregations

ListMultipartUploadsRequest (com.qcloud.cos.model.ListMultipartUploadsRequest)3 MultipartUpload (com.qcloud.cos.model.MultipartUpload)3 MultipartUploadListing (com.qcloud.cos.model.MultipartUploadListing)3 AbortMultipartUploadRequest (com.qcloud.cos.model.AbortMultipartUploadRequest)2 Test (org.junit.Test)1