Search in sources :

Example 6 with AbortMultipartUploadRequest

use of com.qcloud.cos.model.AbortMultipartUploadRequest 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 7 with AbortMultipartUploadRequest

use of com.qcloud.cos.model.AbortMultipartUploadRequest 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)

Example 8 with AbortMultipartUploadRequest

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

the class UploadCallable method performAbortMultipartUpload.

/**
 * Performs an {@link COS#abortMultipartUpload(AbortMultipartUploadRequest)} operation for the
 * given multi-part upload.
 */
void performAbortMultipartUpload() {
    try {
        if (multipartUploadId != null) {
            AbortMultipartUploadRequest abortMultipartUploadRequest = new AbortMultipartUploadRequest(origReq.getBucketName(), origReq.getKey(), multipartUploadId);
            TransferManagerUtils.populateEndpointAddr(origReq, abortMultipartUploadRequest);
            cos.abortMultipartUpload(abortMultipartUploadRequest);
        }
    } catch (Exception e2) {
        log.info("Unable to abort multipart upload, you may need to manually remove uploaded parts: " + e2.getMessage(), e2);
    }
}
Also used : AbortMultipartUploadRequest(com.qcloud.cos.model.AbortMultipartUploadRequest) CancellationException(java.util.concurrent.CancellationException)

Aggregations

AbortMultipartUploadRequest (com.qcloud.cos.model.AbortMultipartUploadRequest)8 CosServiceException (com.qcloud.cos.exception.CosServiceException)4 CosClientException (com.qcloud.cos.exception.CosClientException)3 ResponseNotCompleteException (com.qcloud.cos.exception.ResponseNotCompleteException)2 ListMultipartUploadsRequest (com.qcloud.cos.model.ListMultipartUploadsRequest)2 MultipartUpload (com.qcloud.cos.model.MultipartUpload)2 MultipartUploadListing (com.qcloud.cos.model.MultipartUploadListing)2 IOException (java.io.IOException)2 CancellationException (java.util.concurrent.CancellationException)2 COSClient (com.qcloud.cos.COSClient)1 ClientConfig (com.qcloud.cos.ClientConfig)1 BasicCOSCredentials (com.qcloud.cos.auth.BasicCOSCredentials)1 COSCredentials (com.qcloud.cos.auth.COSCredentials)1 COSObject (com.qcloud.cos.model.COSObject)1 CompleteMultipartUploadRequest (com.qcloud.cos.model.CompleteMultipartUploadRequest)1 CompleteMultipartUploadResult (com.qcloud.cos.model.CompleteMultipartUploadResult)1 CopyObjectRequest (com.qcloud.cos.model.CopyObjectRequest)1 CopyPartRequest (com.qcloud.cos.model.CopyPartRequest)1 DeleteObjectRequest (com.qcloud.cos.model.DeleteObjectRequest)1 GetObjectMetadataRequest (com.qcloud.cos.model.GetObjectMetadataRequest)1