You need to sign in to do that
Don't have an account?
JeffreyStevens
Amazon S3 API calls
I'm trying to call the Amazon S3 API from Apex, but keep getting a
System.HttpResponse[Status=Forbidden, StatusCode=403] error.
I know my end-points, key and secret are correct - as I pasted them directly from a working Postman example.
Can anyone see issues with my code?
Thanks!
System.HttpResponse[Status=Forbidden, StatusCode=403] error.
I know my end-points, key and secret are correct - as I pasted them directly from a working Postman example.
Can anyone see issues with my code?
Thanks!
public list<string> rtnBucketItems(string bucketName, string key, string secret) { if(bucketName==null) bucketName = '******************************'; if(key==null) key = '******************************'; if(secret==null) secret = '******************************'; String currentTimestamp = datetime.now().formatGmt('EEE, dd MMM yyyy HH:mm:ss Z'); list<string> bucketItems = new list<string>(); Http http = new Http(); HttpRequest request = new HttpRequest(); request.setMethod('GET'); request.setHeader('Host','******************************.s3.amazonaws.com'); request.setHeader('Content-Encoding', 'base64'); request.setHeader('Date',currentTimestamp); request.setEndpoint('https://******************************.s3.amazonaws.com'); // Build and set Authorization Header string stringToSign = 'GET\n\n\n' + currentTimestamp + '\n\n/' + bucketName; string stringSigned = rtnSignedString(stringToSign, secret); string authHeader = 'AWS' + ' ' + key + ':' + stringSigned; request.setHeader('Authorization', authHeader); HttpResponse response = http.send(request); system.debug('response='+response); return bucketItems; } public string rtnSignedString(string inString, string secret) { string signedString; Blob mac = Crypto.generateMac('HMACSHA1',blob.valueOf(inString),blob.valueOf(secret)); signedString = EncodingUtil.base64Encode(mac); return signedString; }
Sorry for this issue you are facing.
May I suggest you please refer to below link from the stack exchange community with a similar discussion which might help you further.
- https://salesforce.stackexchange.com/questions/205251/error-while-uploading-file-to-s3-from-apex
Please let us know if this helps.Kindly mark this as solved if the reply was helpful.
Thanks,
Nagendra
Thanks,