NavinRaj Pandey
NavinRaj Pandey

Reputation: 1704

Amazon s3 strange error while uploading image. Please suggest

Using the following code in my Android activity:

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      
        );

got the error: Error during upload: 1

com.amazonaws.services.s3.model.AmazonS3Exception: The bucket you are attempting to access must be addressed using the specified endpoint

Upvotes: 0

Views: 96

Answers (1)

NavinRaj Pandey
NavinRaj Pandey

Reputation: 1704

this really worked for me Thanks @Khalid for your suggestion it was needed too (this code made the image url publicly accessible as well):

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);

Upvotes: 1

Related Questions