I need to send a file of max size 25 mb to my server side controller function from lightning component. I need to pass values to server, create record and then assign the file to it

I am using of type file.

Not using fileupload component as it asks for the record id as I donot have it at he time of passing the record.


I went through below: http://peterknolle.com/file-upload-lightning-component/ http://sfdcmonkey.com/2017/09/25/file-upload-lightning-component/

any suggestions would be helpful

4 Answers 4


You could use lightning:recordeditform or force:recorddata to create the record on the client side and access the Id to use with the lightning:fileUpload component. See the link below: https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/data_service.htm


One of the ways I have used in the past (when lightning:fileUpload was not available) is to create a VF page specifically for file uploads, and then embed that VF page in a Lightning Component using iframe.

Your VF (say its named as MyFileUploadVF.page) would consist something as below:

<apex:inputFile id="componentId" value="{!attachment.body}" filename="{!attachment.name}"/>

And then in your Lightning Component, you can embed this using an iframe, something as below:

<iframe src="https://<instance-url>/apex/MyFileUploadVF"
                      width="298px" height="300px" frameBorder="0"/>

Use lightning:fileUpload attaching the file to the User record, and then handle the event that returns you the ContentDocumentId. Once the target record is created, you can create a ContentDocumentLink from the new record to the uploaded file.


I tried with a workaround, while loading the page itself created a recordID in the background and passed this id to lightning:fileupload , which enabled and I am able to attach the file.

If for some reason, user wants to drop the idea of creating the record and he clicks on cancel button, I delete the record if he/she was creating a record and not updating it.

You must log in to answer this question.

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