3

I want to integrate Amazon S3 API with Salesforce Lightning component in order to upload/download files directly from the client's browser (not from the APEX server controller). I use newest Javascript AWS library -> version 2.205. It is copied in the static resource.

Problem appears when setting Lightning component Bundle version newer than 39.0. In that case callback function is not fired at all, but everything works perfectly when version is below 40.0. I guess this is because LockerService is automatically enabled for newer API version, but don't know why it disables callbacks. I need biger version because of using new standard lightning components.

Is there anyone who ran into similar problem and does someone know the solution?

Here is a client side code sample for retreiving files:

AWS.config.credentials = new AWS.Credentials(accessKeyId, secretAccessKey, null);

var s3 = new AWS.S3({region : 'eu-west-2', apiVersion: '2015-12-08'});

var params = {Bucket: "test", 
              Key: "test.jpg"}

s3.getObject(params, function(err, data) {
    if (err) {
        console.log(err);
    } else {
        console.log(data);
    }
});
  • Are you getting any specific errors in the browser console? Are you using CSP Trusted Sites to whitelist the AWS servers? help.salesforce.com/… – Charles T Mar 7 '18 at 12:48
  • Yes, I added amazon's URL to Trusted sites, as well as in the remote sites. I'm not getting any error, just callback is not fired at all. when I downgrade the version it is called properly – Ante Čabraja Mar 7 '18 at 13:33
  • When you check in the browser's console under Network do you see any evidence that it ever made the callout at all? – Charles T Mar 7 '18 at 14:59
  • Yes, response is there in the Network tab – Ante Čabraja Mar 7 '18 at 15:33
  • Try playing with $A.getCallback() – dzh Mar 7 '18 at 21:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.