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
sakshi Gandhi 8sakshi Gandhi 8 

Get object detail from s3

Hello,

​The only thing we need is to get the folder contents to display in our VF page.
See the below link, which shows how to retrieve details using Java but the same is not working in APEX.
 
http://stackoverflow.com/questions/8932469/how-can-i-non-recursively-browse-the-contents-of-a-directory-with-the-aws-s3-api
 
Any help will be greatly appreciated.

And below is my code returning all objects under bucket.But I need to get detail of specific object.

global with sharing class SalesForceAmazonWSGetContent{
 
    public void GetObject(){
      
       string timestamp = Datetime.now().format('EEE, dd MMM yyyy HH:mm:ss z','America/Denver');
        string bucket = mybucket;
        String key = 'key.....use your key';
        string method = 'GET';
        string foldername = 'myfolder';
        string secret = 'secret......use your secret';
        string stringToSign= method+'\n\n'+ '' +'\n'+ timestamp+'\n/'+bucket+'/'+foldername;
        Blob bsig = Crypto.generateMac('hmacSHA1',Blob.valueOf(stringToSign),Blob.valueof(secret));
        string Signature= EncodingUtil.base64Encode(bsig);
        HttpRequest req = new HttpRequest();
        req.setMethod(method);
        req.setHeader('Host','s3.amazonaws.com');
        req.setEndpoint('https://s3.amazonaws.com'+ '/'+ bucket+ '/' + foldername);
        Http http = new Http();
        req.setHeader('Authorization','AWS '+key+':'+signature);
        req.setHeader('Date',timestamp);
        
        HttpResponse res = http.send(req);
        system.debug('+++++Body is'+res.getBody());
       
    }
  
}
 
Best Answer chosen by sakshi Gandhi 8
sakshi Gandhi 8sakshi Gandhi 8
Got the solution

       req.setEndpoint('https://s3.amazonaws.com'+'/'+bucket+'?prefix=LAI-00001/Lead/&delimiter=/');


Need to set endpoint as above

All Answers

Daniel BallingerDaniel Ballinger
I'm not an expert on the Amazon S3 API. However, if you want the details for a specific object under your bucket I would assume that you need to modify the endpoint URL to indicate which object you want.

If you know the object details your could use it directly. Otherwise you will probably need to parse the response to your current request.

See also: GET object (http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectGET.html).
sakshi Gandhi 8sakshi Gandhi 8
I am able to list alll objects under bucket .I need to get specific bucket detail from s3
sakshi Gandhi 8sakshi Gandhi 8
Got the solution

       req.setEndpoint('https://s3.amazonaws.com'+'/'+bucket+'?prefix=LAI-00001/Lead/&delimiter=/');


Need to set endpoint as above
This was selected as the best answer