[SalesForce] Upload and store 50 MB file from LWC

I have a LWC that, is retrieving the body of an attachment using apex. This is retrieved just as blob, because handling it in Apex would hit limits such as String too long os Heap Size exceeded, cause the attachment may be 50MB, so to handle it I am using atob function in my LWC JS Controller.

Reading it is working just fine, but I want to be able to edit it as well, and I am afraid of
facing any limit, like heap size, with a method like this one.

public static void upsertAttachment(Attachment att) {
    upsert att;

Is this even possible?

I think that basically will leave no time for the heap size limit checker to run, so nothing will be detected, but I do not want to run into that issue if I am wrong.

Is there any good alternative for this?

We are an ISV and this code will be managed, in the past we were using Visualforce and Static resource leveraging AJAX toolkit, but I think locker service will no longer allow this, and we may run into problems with the security review

Best Answer

There's a maximum payload for LWC components (~4MB last I checked), and there's also a maximum String size, clamped at Limits.getLimitHeapSize() (so, 6MB for an AuraEnabled method); you'd get away with not much more than a 4.5MB file even if there was a larger payload limit, since you'd have to base64 encode the file data. You might be able to use the Lightning Data Service createRecord() function directly. The documentation is not clear if that will actually work (it makes no mention of Blob data types), but it'd be your best bet. Also, you could directly use lightning-file-upload, which I know specifically supports up to 2GB files.