function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
RajusRajus 

Get bucket objects from amazon s3 using rest api

Hi All,

 

I am facing an issue while trying to get the  bucket objects from amazon s3 using rest api.Could any one please help me out on this.

 

Following is my code:

 

string timestamp = datetime.now().formatGmt('EEE, d MMM yyyy HH:mm:ss Z');
string bucket = 'xyz';
string stringToSign='GET\n\n\n'+timestamp+'\n/'+bucket+'/';
Blob bsig = Crypto.generateMac('hmacSHA1',Blob.valueOf(stringToSign),Blob.valueof('xxxxxxxxxxxxxxxxxxxxx'));
string Signature= EncodingUtil.base64Encode(bsig);
HttpRequest req = new HttpRequest();
string endpoint = 'https://s3.amazonaws.com';
req.setMethod('GET');
req.setHeader('Host',bucket+'.'+'s3.amazonaws.com');
req.setEndpoint(endpoint);
Http http = new Http();
string AWSAccessKeyId='xxxxxxxxxxxxxxxx';
req.setHeader('Authorization','AWS '+AWSAccessKeyId+':'+signature);
req.setHeader('Date',timestamp);
HttpResponse res = http.send(req);
system.debug('Body is'+res.getBody());

 

I am getting the Signature mismatch error for the above code.Any guidence appreciated.

 

 

Thanks,

Raj

 

S3-LinkS3-Link
S3- Link is FREE App for Salesforce - Amazon Connector. Its also available on Appexchange. 
 

    Attach file related to any Salesforce object on Amazon.
    Ulimited free storage for one year.
    Multiple file uplaod.
    No file size limit for upload.
    File access control capabiliy.
    Track file downloads by users.
    File exlorer capability.

https://appexchange.salesforce.com/listingDetail?listingId=a0N3000000CW1OXEA1

Here is our email address. Let us know if you have any query.
support@neiloncloud.com

Thanks.