I have implemented custom file upload component using input file html tag and rendering it as browse file button.

The issue with component is:-

  • When trying to upload file more than 4 mb of size, i am getting below error:-

[AuraClientInputException from server] Unexpected request input. Expected input format: "Max message parameter length is 4194304 characters.".

It seems apex heap size error.

How i am reading the file uploaded?

I am using the FileReader Api to read it and fire an apex method to save the file as ContentVersion Object record in Salesforce.

this.fileReader = new FileReader();
            // set onload function of FileReader object  
            this.fileReader.onloadend = (() => {
                this.filecontent = this.fileReader.result;
                let base64 = 'base64,';
                this.content = this.filecontent.indexOf(base64) + base64.length;
                this.filecontent = this.filecontent.substring(this.content);
                //saving the file by calling an apex method
                    parentId: 'a8pq00000001w4QAAQ', fileName: this.fileName,
                    base64Data: encodeURIComponent(this.filecontent)
                }).then(result => {
                    window.console.log('result ====> ' + result);
                    .catch(error => {
                        // Showing errors if any while inserting the files

Why i can't use Lightning FileUpload component?

This component uploads the document as soon user select the file in browse window,but our aim is to upload files only when we click a specific upload button. It also does not have maximum file size attribute.

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.