【问题标题】:How to get the progress of copy operation in AWS copy operation in android?如何在android中的AWS复制操作中获取复制操作的进度?
【发布时间】:2020-06-03 11:12:29
【问题描述】:

我尝试将一个文件从一个文件夹复制到同一个存储桶内的另一个文件夹。为了复制文件,我使用 CopyObjectRequest 类。但我不知道如何获得复制操作的进度? 所以请帮助我,我怎样才能得到复制操作的进度状态。

对于复制操作,我遵循这种方式-

try {
        AmazonS3 s3Client =new AmazonS3Client(credentials,cc);

        // Copy the object into a new object in the same bucket.
        CopyObjectRequest copyObjRequest = new CopyObjectRequest(bucketName, sourceKey, "wedorias-new", "test/test111/logo.png"/*destinationKey*/);
        s3Client.copyObject(copyObjRequest);

        if (copyObjRequest.isRequesterPays()){

            System.out.println("sadfbgnh==");
        }

    } catch (AmazonServiceException e) {
        // The call was transmitted successfully, but Amazon S3 couldn't process
        // it, so it returned an error response.
        e.printStackTrace();
        System.out.println("exception==!"+e.getErrorMessage());
        System.out.println("exception==!"+e.getErrorCode());
        System.out.println("exception==!"+e.getMessage());
    } catch (Exception e) {

        e.printStackTrace();
        System.out.println("exception==!"+e.getMessage());
    }

【问题讨论】:

    标签: android amazon-web-services amazon-s3 aws-lambda


    【解决方案1】:

    如果您想将一个对象从一个文件夹复制到另一个文件夹(或其他存储桶,如果是这种情况)并检查进度,您必须使用Amazon S3 Multipart Upload

    AWS 文档有一个很好的示例,名为 Copy an Object Using the AWS SDK for Java Multipart Upload API,它向您展示了设置它和检查副本进度所需的操作。

    // Get the object size to track the end of the copy operation. 
    GetObjectMetadataRequest metadataRequest = new GetObjectMetadataRequest(sourceBucketName, sourceObjectKey); 
    ObjectMetadata metadataResult = s3Client.getObjectMetadata(metadataRequest); 
    long objectSize = metadataResult.getContentLength();
    

    通知

    • 当对象大于 5GB 时,必须分段上传。

    • 当对象大于 100MB 时,建议分段上传。

    • 如果对象小于 5MB,分段上传将不起作用。

    【讨论】:

    • 感谢您的回答。我可以知道我怎样才能得到相同的删除操作?
    • 很高兴我的回答对您有所帮助。我没有尝试过,我认为这是不可能的,但你总是可以打开一个新问题,看看其他人是否可以通过一个很好的解释告诉你它是否可能。
    猜你喜欢
    • 2010-12-02
    • 2010-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多