Hey I am trying to upload an image to s3 bucket my code is:
public static void addObjectToBucketFromStream(AmazonS3 conn,
String bucketName, String keyName, InputStream inputStream,
Map<String, String> metadataMap,String contentType) throws IOException {
try {
ObjectMetadata metadata = new ObjectMetadata();
if (metadataMap != null) {
for (Iterator iterator = metadataMap.keySet().iterator(); iterator
.hasNext();) {
String key = (String) iterator.next();
String value = metadataMap.get(key);
metadata.addUserMetadata(key, value);
}
}
metadata.setContentLength(inputStream.available());
if (contentType!=null && !"".equals(contentType)){
metadata.setContentType(contentType);
}
PutObjectRequest por = new PutObjectRequest(bucketName, keyName,
inputStream, metadata);
por.setCannedAcl(CannedAccessControlList.PublicRead);
conn.putObject(por);
int a;
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
// ignore
}
}
}
}
In this code putObject() throws com.amazonaws.services.s3.model.PutObjectRequest throws com.amazonaws.services.s3.model.AmazonS3Exception
In log it is showing
com.amazonaws.services.s3.model.AmazonS3Exception: Status Code: 403, AWS Service: Amazon S3, AWS Request ID: 8C576CDFEC92534C, AWS Error Code: AccessDenied, AWS Error Message: Access Denied, S3 Extended Request ID: q7Rs1xrUbnJgptnJKS5T5qhPc6Y3NT66qaGGA5or6as0i0JloLAYODiHcoztD+seWyExpVHM4ls=