Amazon Simple Storage Service
开发人员指南 (API 版本 2006-03-01)
AWS 文档中描述的 AWS 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 Amazon AWS 入门

中止分段上传

以下示例使用高级别 Java API (TransferManager 类) 中止一周前在特定存储桶上启动的正在进行的所有分段上传。有关创建和测试有效示例的说明,请参阅测试 Amazon S3 Java 代码示例

import java.util.Date; import com.amazonaws.AmazonServiceException; import com.amazonaws.SdkClientException; import com.amazonaws.auth.profile.ProfileCredentialsProvider; import com.amazonaws.services.s3.AmazonS3; import com.amazonaws.services.s3.AmazonS3ClientBuilder; import com.amazonaws.services.s3.transfer.TransferManager; import com.amazonaws.services.s3.transfer.TransferManagerBuilder; public class HighLevelAbortMultipartUpload { public static void main(String[] args) { String clientRegion = "*** Client region ***"; String bucketName = "*** Bucket name ***"; try { AmazonS3 s3Client = AmazonS3ClientBuilder.standard() .withRegion(clientRegion) .withCredentials(new ProfileCredentialsProvider()) .build(); TransferManager tm = TransferManagerBuilder.standard() .withS3Client(s3Client) .build(); // sevenDays is the duration of seven days in milliseconds. long sevenDays = 1000 * 60 * 60 * 24 * 7; Date oneWeekAgo = new Date(System.currentTimeMillis() - sevenDays); tm.abortMultipartUploads(bucketName, oneWeekAgo); } catch(AmazonServiceException e) { // The call was transmitted successfully, but Amazon S3 couldn't process // it, so it returned an error response. e.printStackTrace(); } catch(SdkClientException e) { // Amazon S3 couldn't be contacted for a response, or the client couldn't // parse the response from Amazon S3. e.printStackTrace(); } } }