Uploading file in contentVersion using lightning component

I am developing a lightning component to upload files in a contentversion object. I am referring to this site : 

http://webcache.googleusercontent.com/search?q=cache:yDEYXecmDHMJ:peterknolle.com/file-upload-lightning-component/+&cd=1&hl=en&ct=clnk&gl=in

I was successful uploading files up to 3 MB without chunking but I am facing some issues in chunking the file to upload the large files.
Wherever I upload the file, it gives me the following error :
System.StringException: Unrecognized base64 character: %
I am attaching code for the helper class and apex controller.

I am also trying to upload the large files using the CHUNKING but it was not working for the ContentVersion because by default IsMajorVersion field in the ContentVersion object is TRUE and it's not updatable also. So While inserting the ContentVersion makes IsMajorVersion false so CHUNKING will work in the ContentVersion object.

ContentVersion cVersion = new ContentVersion();
cVersion.ContentLocation = 'S'; //S-Document is in Salesforce. E-Document is outside of Salesforce. L-Document is on a Social Netork.
cVersion.PathOnClient = '/' + finalFileName;//File name with extention
cVersion.Origin = 'H';//C-Content Origin. H-Chatter Origin.
cVersion.OwnerId = UserInfo.getUserId();//Owner of the file
cVersion.Title = finalFileName;//Name of the file
cVersion.IsMajorVersion = false;
cVersion.VersionData = EncodingUtil.base64Decode(base64Data);//File content
insert cVersion;
Id conDocument = [SELECT ContentDocumentId FROM ContentVersion WHERE Id =:cVersion.Id].ContentDocumentId;
ContentDocumentLink cDocLink = new ContentDocumentLink();
cDocLink.ContentDocumentId = conDocument;//Add ContentDocumentId
cDocLink.LinkedEntityId = standDesingid;//Add attachment parentId
cDocLink.ShareType = 'V';//V - Viewer permission. C - Collaborator permission. I - Inferred permission.
cDocLink.Visibility = 'AllUsers';//AllUsers, InternalUsers, SharedUsers
insert cDocLink;

Comments

Popular posts from this blog

Adding a red asterisk to required fields using label in LWC

The Developer Console didn't set the DEVELOPER_LOG trace flag on your user. Having an active trace flag triggers debug logging. You have 1,978 MB of the maximum 1,000 MB of debug logs. Before you can edit trace flags, delete some debug logs.

Salesforce: Serial and Parallel Approval