在s3中使用加速模式时无法解决主机错误

时间:2017-11-02 17:23:20

标签: java android amazon-web-services amazon-s3 amazon

我是amazon aws sdk for java的新手。我有java的aws sdk v2.6。我的问题是当我启用加速模式时 s3Client.setS3ClientOptions(S3ClientOptions.builder().setAccelerateModeEnabled(true).build()); 我得到例外"无法解析主机" s3-accelerate.amazonaws.com":没有与主机名相关的地址"在上传文件。它在以前版本的sdk中运行良好。我不知道如何解决这个问题。任何人都可以帮助我。

1 个答案:

答案 0 :(得分:0)

使用以下代码创建AmazonS3Client解决了我的问题,

    final CountDownLatch countDownLatch = new CountDownLatch(1);

    ClientConfiguration configuration = new ClientConfiguration();
    configuration.setMaxErrorRetry(3);
    configuration.setConnectionTimeout(501000);
    configuration.setSocketTimeout(501000);
    configuration.setProtocol(Protocol.HTTP);

    sS3Client = new AmazonS3Client(AWSMobileClient.getInstance().getCredentialsProvider(), configuration);

    if (sS3Client == null) {
        sS3Client.setRegion(Region.getRegion(Regions.US_EAST_1));
        sS3Client.setS3ClientOptions(S3ClientOptions.builder().setAccelerateModeEnabled(true).build());

        // wrap the call in a thread since we make a network call.
        new Thread(new Runnable() {
            @Override
            public void run() {
                sS3Client.setBucketAccelerateConfiguration(AppConstants.BUCKET_NAME,
                        new BucketAccelerateConfiguration(BucketAccelerateStatus.Enabled));
                countDownLatch.countDown();
            }
        }).start();

        try {
            countDownLatch.await();
        } catch (InterruptedException ie) {
            ie.printStackTrace();
        }
    }

您可以参考此链接https://github.com/aws/aws-sdk-android/issues/473