Salesforce | Visualforce Component to AWS S3

|
| By Webner

Description :

To access the features provided by amazon for storage and cloud computations from a visualforce component , the S3 service uses information from the form’s input fields to authorize uploads, and to set the properties of uploaded file objects.

To get Authorised make sure you got the object and Secret compiled correctly.

Following are the Script code steps to get a correctly compiled object and Signature:

1. Make a JsonString variable with your values like example below:

object_JSON =  { "expiration": "2030-12-12T12:00:00.000Z",
"conditions": [
{"bucket": "YourBucketName"},
["starts-with", "$key",""],
{"acl": "private"},
["starts-with", "$Content-Type", " "],
["content-length-range", 0, 524288000]
]
};

2. Encode the JsonString in base-64 using the btao function as:

var projectBase64 = btoa(JSON.stringify(object_JSON));

3. Now create the signature using the secret key and encoded object as:

var signature = b64_hmac_sha1(secret, objectBase64);

4. Now use the objectBase64 and signature in the request parameters as:

var formData = new FormData();
formData.append('key', “/${filename}");
formData.append('acl', "private");
formData.append('Content-Type', " ");
formData.append('AWSAccessKeyId', "your key");
formData.append('object', objectBase64 )
formData.append('signature',signature);
formData.append("file",files);

var xhr = new XMLHttpRequest();
xhr.open('POST', 'https://bucketname.s3.amazonaws.com/', true);
//MUST BE LAST LINE BEFORE YOU SEND
xhr.send(formData);

Webner Solutions is a Software Development company focused on developing CRM apps (Salesforce, Zoho), LMS Apps (Moodle/Totara), Websites and Mobile apps. If you need Salesforce customization, App development or any other software development assistance please contact us at salesforce@webners.com

Leave a Reply

Your email address will not be published. Required fields are marked *