1

我想使用 AmazonAWS TransferManager 上传目录。我使用来自 TVM 的凭据成功创建了 AmazonS3Client。

当我尝试用它下载文件时,它抱怨:

final MultipleFileDownload fileDownloadd=mTransferManager.downloadDirectory(ChanAuth.getBucketName(), remotePath, file);

AWS 错误代码:PermanentRedirect,AWS 错误消息:您尝试访问的存储桶必须使用指定的终端节点进行寻址。请将所有未来的请求发送到此端点

我已经阅读了有关该主题的内容,并且过去曾在其他编程语言中体验过它。我记得它与您在发出 S3 命令时执行最终“发布”的位置有关(我必须直接发布到我的存储桶 url)。但错误来自 AWS 开发工具包的深处,应该在那里处理。

我的存储桶位于 EU-WEST-1 区域。

我用

s3Client.setRegion(Regions....(Region.EU_WEST_1))

s3Client.setEndpoint("s3-eu-west-1.amazonaws.com");

但我总是让 TransferManager 抱怨。

我怀疑这一定是一个愚蠢的问题,但我陷入了 AwS SDK 的数百万行和方法中。必须在某个地方正确设置端点,否则 sdk 将不适用于美国地区以外的存储桶。

帮助赞赏:)

            06-09 20:16:02.810: D/SynchroService(4408): MESSAGE: nicebeat SYNC
            06-09 20:16:02.810: D/SynchroService(4408): MESSAGE: downlading from chd68f38e7d1360dc1d999354da4f98601/nicebeat/story/sonidonia to /mnt/sdcard/Android/data/com.regaliz.libneo/files/nicebeat/story/sonidonia/lib
            06-09 20:16:02.810: D/SynchroService(4408): is directory? true
            06-09 20:16:03.490: W/System.err(4408): AmazonS3Exception: Status Code: 301, AWS Service: Amazon S3, AWS Request ID: 2695AE32DC39077E, AWS Error Code: PermanentRedirect, AWS Error Message: The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint., S3 Extended Request ID: j9zQ8EBzkCGHkRTveri82HoA/Yh9PvJofUPtNJlc9oKrVutG0VjNEGG90WnTGaN4
            06-09 20:16:03.490: W/System.err(4408):     at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:633)
            06-09 20:16:03.490: W/System.err(4408):     at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:327)
            06-09 20:16:03.490: W/System.err(4408):     at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:179)
            06-09 20:16:03.490: W/System.err(4408):     at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:2980)
            06-09 20:16:03.490: W/System.err(4408):     at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:2951)
            06-09 20:16:03.490: W/System.err(4408):     at com.amazonaws.services.s3.AmazonS3Client.listObjects(AmazonS3Client.java:479)
            06-09 20:16:03.490: W/System.err(4408):     at com.amazonaws.services.s3.transfer.TransferManager.downloadDirectory(TransferManager.java:588)
            06-09 20:16:03.490: W/System.err(4408):     at com.regaliz.services.Synchro.downloadDirectory(Synchro.java:156)
            06-09 20:16:03.490: W/System.err(4408):     at com.regaliz.services.Synchro.request_commands(Synchro.java:99)
            06-09 20:16:03.490: W/System.err(4408):     at com.regaliz.services.Synchro$3.run(Synchro.java:195)
4

2 回答 2

1

您需要设置与创建存储桶的位置匹配的端点。

例如:如果“mybucket”是在 EU 下创建的,那么对于您正在创建的 s3client,应将端点设置为“s3-eu-west-1.amazonaws.com”。

同样,根据您的存储桶的创建位置,您可以根据此页面设置端点:http: //docs.aws.amazon.com/general/latest/gr/rande.html#s3_region

于 2013-07-15T17:58:32.060 回答
-1

对于来自不同地区、不同端点的用户可以参考: http ://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region

如果您不知道您的端点到底是什么,您可以遍历所有端点并尝试每个端点,并在正确的端点上归零。

private String[] endPoints = new String[] { "s3.amazonaws.com",
            "s3-external-1.amazonaws.com", "s3-us-west-2.amazonaws.com",
            "s3-us-west-1.amazonaws.com", "s3-eu-west-1.amazonaws.com",
            "s3-ap-southeast-1.amazonaws.com",
            "s3-ap-southeast-2.amazonaws.com",
            "s3-ap-northeast-1.amazonaws.com", "s3-sa-east-1.amazonaws.com" };

private int currentIndex = 0;

protected S3TaskResult upload(String filePath) {
        String endPoint = endPoints[currentIndex++];

        S3TaskResult result = new S3TaskResult();

        // Put the image data into S3.
        try {
            // s3Client.createBucket(Constants.getPictureBucket());"

            s3Client.setEndpoint(endPoint);
            // Content type is determined by file extension.
            PutObjectRequest por = new PutObjectRequest(
                    Constants.getPictureBucket(), Constants.PICTURE_NAME,
                    new java.io.File(filePath));
            por.setProgressListener(this);
            s3Client.putObject(por);

            Log.d("S3","SUCCESSFUL ENDPOINT : "+endPoint); // GOT IT!!

        } catch (Exception exception) {
            if (currentIndex < endPoints.length) {
                upload(filePath);

            } 
            exception.printStackTrace();
        }

        return result;
    }
于 2013-10-04T18:49:21.370 回答