I have lwc component like:

import { LightningElement } from 'lwc';
import {saveAttachment} from '@salesforce/apex/DocumentController.saveAttachment'

export default class FileUpload extends LightningElement {

  fileSelectionHandler() {
   // some logic to get the file
  uploadFile() {
    saveAttachment({parentId: 'a0H3I000001SsylUAC'})
    .then(() => {
     // some code here
    .catch(() => {
    // some code here


and its html template is:

  <input type="file" onchange={fileSelectionHandler}>
  <button onclick={}>Upload</button>

And apex class like this:

public without sharing class DocumentController {

  public static string saveAttachment(String parentId) {
    Attachment attach = new Attachment();
    attach.Name = 'test.pdf';
    attach.ParentId = parentId;
    // attach.Body ==> this part should come from lwc

    insert attach;
    return attach.Id;

What I need is someway by which we can directly connect attach in apex class above to the template so that I can directly get the blob to the attach in apex class like we have for visualforce page input file component below

<apex:inputfile style="" value="{!attach.body}" filename="{!attach.name}" contentType="{!attach.ContentType}"/>

Here we directly assign the file selected to attach.body, Similarly is there any by which we can directly bind attach to lwc so that blob is available in attach.Body. This would help me in uploading large attachments like upto 25MB without hitting the heap size issue with apex.

Any help would be greatly appreciated. Thanks in Advance.

Please note: Since I am using lighning out, lightning-file-upload cant be used here

  • you can use ConnectApi's Rest API . It supports 2GB
    – Ysr Shk
    Aug 20, 2020 at 17:39

1 Answer 1


You'll have to use some sort of API. Apex has a 6MB heap limit, so you'd run into it regardless (binding directly wouldn't help), and also there's a maximum payload size (4MB), so the largest file you'd reasonably upload is around 3MB, include base64 encoding.

  • Hi @sfdcfox Thanks, I tried uploading attachments using connection.js. I was able to upload 25MB. But only issue I am facing now is I have to make this available for site guest user. Since guest user don't have an API session ID I cant use connection.js. With APEX we have 4MB payload limit as you said. Can you please suggest me any alternative or workaround ?
    – AdityaHM
    Sep 10, 2020 at 16:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .