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());
}
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());
}
}
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);
}
}
Aggregations