上传图片时亚马逊s3奇怪的错误。请建议

时间:2017-02-20 03:44:18

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

在我的Android活动中使用以下代码:

CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(
                getApplicationContext(),    
                "eu-central-1:XXXXXXXXXXXXXXXXXXXXX",    
                Regions.EU_CENTRAL_1           
        );

        AmazonS3 s3 = new AmazonS3Client(credentialsProvider);
        TransferUtility transferUtility = new TransferUtility(s3, getApplicationContext());

       File file= new File("/storage/extSdCard/Sweee/app/src/main/res/mipmap-xxhdpi/ic_launcher.png");
        TransferObserver observer = transferUtility.upload(
                "aaa.bbb",     
                "test"+file.getName(),    
               file      
        );

收到错误:上传时出错:1

  

com.amazonaws.services.s3.model.AmazonS3Exception:你是桶   必须使用指定的端点

来寻址尝试访问

1 个答案:

答案 0 :(得分:1)

这真的对我有用感谢@Khalid你的建议它也是需要的(这段代码也使得图片网址也可公开访问):

BasicAWSCredentials basicAWSCredentials=new BasicAWSCredentials("XXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXX");
            AmazonS3 aS3 = new AmazonS3Client(basicAWSCredentials);
            aS3.setEndpoint("https://s3-eu-central-1.amazonaws.com/");

            File file= new File("/storage/extSdCard/Sweee/app/src/main/res/mipmap-xxhdpi/ic_launcher.png");

            PutObjectRequest putObj=new PutObjectRequest("aaa.bbbb", "test_navin1/"+file.getName(),file);

            //making the object Public
            putObj.setCannedAcl(CannedAccessControlList.PublicRead);

            aS3.putObject(putObj);