You need to sign in to do that
Don't have an account?
Tu Dao
How to Upload an Attachment to Amazon S3 using REST Interface
Hi all,
I implemented a method to upload an Attachment to Amazon S3 but I'm having this issue : AWS authentication requires a valid Date or x-amz-date header
Any help is appreciated.
Attachment attachment = [Select Id, ContentType, Body, BodyLength from Attachment limit 1]; //Set<Id> ids = new Map<Id,Attachment>(attachments).keySet(); AWSKeys credentials = new AWSKeys('Keys'); S3.AmazonS3 as3 = new S3.AmazonS3(credentials.key,credentials.secret); Datetime now = DateTime.now(); String formattednow = now.formatGmt('yyyy-MM-dd')+'T'+now.formatGmt('HH:mm:ss')+'.'+now.formatGMT('SSS')+'Z'; String stringtosign = 'PUT \n\n'; stringtosign += attachment.ContentType + '\n'; stringtosign += formattednow + '\n'; stringtosign += '/mybucket/' + attachment.Id; Blob mac = Crypto.generateMac('HMacSHA1', blob.valueof(stringtosign),blob.valueof(as3.secret)); String signature = EncodingUtil.base64Encode(mac); HttpRequest req = new HttpRequest(); //Set HTTPRequest Method req.setMethod('PUT'); //Set HTTPRequest header properties req.setHeader('content-type', attachment.ContentType); req.setHeader('Content-Length',String.valueOf(attachment.BodyLength)); req.setHeader('Date', formattednow); req.setHeader('Authorization', 'AWS ' + as3.key + ':' + signature); req.setEndpoint('http://s3.amazonaws.com'); try { Http http = new Http(); //Execute web service call here HTTPResponse res = http.send(req); } catch(System.CalloutException e) { System.debug('===================EXCEPTION ' + e.getMessage() + e.getStackTraceString()); }
Hi,
Did you get the solution.
I have kind of same need here.
Regards
Prabhan
Hi,
I have similar kind of issue.Did u able to solve this issue.
I created a date that is 100 years into the future. I don't want the uploaded file to expire.
I want to implement same kind of requirement.
Can you please provide me a steps to implement above method to upload an attachment to Amazon S3
Thanks.
- Drag and Drop interface to upload file
- You can view/delete your files from Salesforce
- Its free
Also they provide Good Support if you have any issues & they provide additional customizations.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.