Question

Unable to upload images into spaces, Error 403. Using Android/Java.

Posted May 12, 2020 496 views
ApplicationsDigitalOcean Spaces

Hi,

I’m trying to upload images, but I’m having problems.

When I upload it returns the error below:

com.amazonaws.services.s3.model.AmazonS3Exception:  (Service: Amazon S3; Status Code: 403; Error Code: 403 Forbidden; Request ID: tx00000000000001bed1de2-005ebb0c82-1cff85-nyc3b), S3 Extended Request ID: null
        at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:730)
        at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:405)
        at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:212)
        at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:4912)
        at com.amazonaws.services.s3.AmazonS3Client.putObject(AmazonS3Client.java:1960)
        at com.amazonaws.mobileconnectors.s3.transferutility.UploadTask.uploadSinglePartAndWaitForCompletion(UploadTask.java:277)
        at com.amazonaws.mobileconnectors.s3.transferutility.UploadTask.call(UploadTask.java:115)
        at com.amazonaws.mobileconnectors.s3.transferutility.UploadTask.call(UploadTask.java:60)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:919)

Upload Code:

StaticCredentialsProvider credentials = new StaticCredentialsProvider(
new BasicAWSCredentials(context.getString(R.string.spaces_key),
context.getString(R.string.spaces_secret)));

AmazonS3Client s3 = new AmazonS3Client(credentials,Region.getRegion("us-east-1"));
                    s3.setEndpoint(context.getString(R.string.spaces_endPoint));

transferUtility = TransferUtility.builder().s3Client(s3).context(context).build();

TransferObserver observer = transferUtility.upload("",folder+"/"+nomeFoto,
file.getFileArquivo(),CannedAccessControlList.PublicReadWrite);

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
2 answers

Are you using a read only token maybe ?

Hello, @contato46fcfbc52233c726d3c

Have you tried to purge the cache if you have the CDN option enabled on your Space? Also in the CORS Configurations make sure you have the GET, PUT and POST methods allowed as well.

If this is not working I will recommend you to contact our support team and they will assist you with the issue.

https://www.digitalocean.com/support/

Hope that helps!

Regards,
Alex

Submit an Answer