java - PutObjectRequest.putObject() method of com.amazonaws.services.s3.model.PutObjectRequest throws com.amazonaws.services.s3.model.AmazonS3Exception -


hey trying upload image s3 bucket 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) {             (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;     } {         if (inputstream != null) {             try {                 inputstream.close();             } catch (ioexception e) {                 // ignore             }         }     } } 

in code putobject() throws com.amazonaws.services.s3.model.putobjectrequest throws com.amazonaws.services.s3.model.amazons3exception

in log 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=

a 403 error indicates problem aws credentials. credentials using amazons3 object? default, they'll located in ~/.aws/credentials.

you can verify credentials correct aws command-line tool. if haven't used before, run aws configure , enter creds. can attempt upload file aws s3 cp somefile s3://mybucket.

if succeeds, can enable java sdk logging documented here more information.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -