1

Trying to figure out how best to build interfaces that retrieve external files between 1-10 MB and display them in the UI.

Right now I have a Lightning Aura Component that calls a web service via HttpRequest and retrieves file metadata, so that users can browse externally stored files. A second HttpRequest allows the user to either preview or download these files, depending on file type. Both methods are synchronous currently.

This works, but the current version has to cap file sizes for preview/download at around 5.7 MB, based on the "Maximum size of callout request or response (HTTP request or Web services call)" governor limit of 6 MB.

We have also been concerned about the "Number of synchronous concurrent transactions for long-running transactions that last longer than 5 seconds for each org" governor limit, which we could easily hit if there are multiple users requesting files larger than 1 MB at the same time that other long-running synchronous processes are executing in our org.

Needless to say, I was enthused when I heard that asynchronous processing was coming to Aura Components in Summer '19 in the form of support for Continuations (see release notes). But as I began to test this, I realized my callouts were failing at much lower file size thresholds than 6 MB. Apparently continuations have specific limits listed in the Apex Developer Guide whereby callouts and responses can't exceed 1 MB. Bummer.

Is there a special architecture whereby I can retrieve files of up to 10 MB and display them in the UI, which can be deployed to users at scale?

1

If you go via apex, the heap limitations will apply.

The workaround is to do a callout from javascript. Yes you can do that.

By default, you can’t make calls to third-party APIs from client-side code. Add a remote site as a CSP Trusted Site to allow client-side component code to load assets from and make API requests to that site’s domain.

So if you do a callout from browser, its heap and cpu of device involved and should be alright.

That being said, the thing you have to worry about is, if its an authenticated call, then make sure you dont do a callout from browser passing username and password. Instead do a callout from apex to get access_token and then use that access_token to call 3rd party,

Src: https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/js_api_calls_platform.htm

Not able to call Composite REST request from LWC

  • Thanks Pranay! I may face an uphill struggle trying to get this API CORS-enabled, which would be necessary to use the AJAX approach. But I agree this seems like a viable alternative, and your response gave me the impetus to look into it further. – Matthew Souther Jun 10 at 16:49

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.