You need to sign in to do that
Don't have an account?
Suman Kuch
How to get a file URL from secured amazon s3 using REST API?
Hi,
We need to show around 100 photos on a page, the photos are in secured S3 bucket. and each photo retrieved by photoid. I tried to get blog and convert into string to display on page but the page is taking around 30 secs to load all photos. Is there a way to get photo URL rather getting blob and Ill put that on page (I use iframe to show photo)?
Here is the apex code I'm using for REST api call to get photo by id.
Thanks,
Sumant
We need to show around 100 photos on a page, the photos are in secured S3 bucket. and each photo retrieved by photoid. I tried to get blog and convert into string to display on page but the page is taking around 30 secs to load all photos. Is there a way to get photo URL rather getting blob and Ill put that on page (I use iframe to show photo)?
Here is the apex code I'm using for REST api call to get photo by id.
public void getPhotofromAWS(String photoid){ HttpRequest req = new HttpRequest(); req.setMethod('GET'); //String endpoint ='https://xxxxxx.s3.amazonaws.com/photo'; String bucketName = 'xxxxxx'; String fileName = photoid+'.jpg'; String formattedDateString = Datetime.now().format('EEE, dd MMM yyyy HH:mm:ss z'); req.setHeader('Date', formattedDateString); String stringToSign = 'GET\n\n\n'+formattedDateString+'\n/'+bucketName +'/photo/'+filename; Blob mac = Crypto.generateMac('HMACSHA1', blob.valueof(stringToSign),blob.valueof('aaaaaaaaaAxxxxxxxxxsssssAAAAAAa')); String sig = EncodingUtil.base64Encode(mac); String auth = 'AWS' + ' ' + 'AAAAAAAAAAAAAAA' + ':' + sig; req.setHeader('Authorization',auth); String endpointBase = 'http://' + bucketName + '.s3.amazonaws.com/photo/' + filename; system.debug(' guid '+guid); req.setEndpoint(endpointBase ); Http http = new Http(); HTTPResponse res = http.send(req); //photoString = res.getBody(); photoString='data:'+res.getHeader('Content-Type')+';base64,'+EncodingUtil.base64Encode(res.getBodyAsBlob()); }Please advice.
Thanks,
Sumant
Please check with below link from forums community which helps you to accelerate with above requirement.
- https://developer.salesforce.com/forums/?id=906F0000000MHhoIAG
Kindly mark this as solved if it's resolved.Regards,
Nagendra.