You need to sign in to do that
Don't have an account?
sakshi 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());
}
}
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());
}
}
req.setEndpoint('https://s3.amazonaws.com'+'/'+bucket+'?prefix=LAI-00001/Lead/&delimiter=/');
Need to set endpoint as above
All Answers
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).
req.setEndpoint('https://s3.amazonaws.com'+'/'+bucket+'?prefix=LAI-00001/Lead/&delimiter=/');
Need to set endpoint as above