Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java AWS SDK TransferManager.Upload是否在发生异常时删除已上载的文件部分?_Java_Amazon Web Services_Amazon S3_Aws Sdk - Fatal编程技术网

Java AWS SDK TransferManager.Upload是否在发生异常时删除已上载的文件部分?

Java AWS SDK TransferManager.Upload是否在发生异常时删除已上载的文件部分?,java,amazon-web-services,amazon-s3,aws-sdk,Java,Amazon Web Services,Amazon S3,Aws Sdk,我正在阅读AWS SDK TransferManager文档,无法确定如果在上传过程中出现任何异常,是否会删除已上传的文件部分。到目前为止,我看到的所有示例都没有任何异常情况下的清理代码。如果文件部分留在桶中,可能会导致金钱损失,尤其是如果文件很大 这是一个来自 我是否需要删除catch block中已加载的文件部分,或者AWS SDK将为我管理此部分?嘿,Volha,欢迎使用SO!请你添加一个上传过程的例子(任何代码都很好)@MartinCassidy,刚刚更新,谢谢! public stat

我正在阅读AWS SDK TransferManager文档,无法确定如果在上传过程中出现任何异常,是否会删除已上传的文件部分。到目前为止,我看到的所有示例都没有任何异常情况下的清理代码。如果文件部分留在桶中,可能会导致金钱损失,尤其是如果文件很大

这是一个来自


我是否需要删除catch block中已加载的文件部分,或者AWS SDK将为我管理此部分?

嘿,Volha,欢迎使用SO!请你添加一个上传过程的例子(任何代码都很好)@MartinCassidy,刚刚更新,谢谢!
public static void main(String[] args) throws Exception {
    Regions clientRegion = Regions.DEFAULT_REGION;
    String bucketName = "*** Bucket name ***";
    String keyName = "*** Object key ***";
    String filePath = "*** Path for file to upload ***";

    try {
        AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
                .withRegion(clientRegion)
                .withCredentials(new ProfileCredentialsProvider())
                .build();
        TransferManager tm = TransferManagerBuilder.standard()
                .withS3Client(s3Client)
                .build();

        // TransferManager processes all transfers asynchronously,
        // so this call returns immediately.
        Upload upload = tm.upload(bucketName, keyName, new File(filePath));
        System.out.println("Object upload started");

        // Optionally, wait for the upload to finish before continuing.
        upload.waitForCompletion();
        System.out.println("Object upload complete");
    } 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();
    }
}