I'm trying to upload a file to amazon s3 and im getting 403 error, tried to follow an example provoded by amazon example here is my code:
public boolean uploadFile() {
BasicAWSCredentials basicAWSCredentials = new BasicAWSCredentials(id, secret);
try {
AmazonS3 client = AmazonS3ClientBuilder.standard()
.withRegion(Regions.US_EAST_2)
.withCredentials(new AWSStaticCredentialsProvider(basicAWSCredentials))
.build();
client.putObject(new PutObjectRequest(bucketName, uploadFileName, this.file));
return true;
} catch (AmazonServiceException ase) {
System.out.println("Caught an AmazonServiceException, which " +
"means your request made it " +
"to Amazon S3, but was rejected with an error response" +
" for some reason.");
System.out.println("Error Message: " + ase.getMessage());
System.out.println("HTTP Status Code: " + ase.getStatusCode());
System.out.println("AWS Error Code: " + ase.getErrorCode());
System.out.println("Error Type: " + ase.getErrorType());
System.out.println("Request ID: " + ase.getRequestId());
return false;
} catch (AmazonClientException ace) {
System.out.println("Caught an AmazonClientException, which " +
"means the client encountered " +
"an internal error while trying to " +
"communicate with S3, " +
"such as not being able to access the network.");
System.out.println("Error Message: " + ace.getMessage());
return false;
}
What I was given by my client is the bucket, the id and the secret. If anyone could point out what i'm doing wrong and point me to some example I could look into. I'm new to amazon aws.
id和机密不起作用是一个凭证问题
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.