0

I'm making a component that allows me to make a video with the capture of the desktop camera. In javascript I have '' vidSave.src '' which is the url of the video that was recorded. When I try to record in the files of a specific object the video is recorded but when I download and play it nothing appears. I think my mistake will be here "conVer.VersionData = Blob.valueof (srcVideo);" I don't see what's missing me, any ideas? thanks

Javascript:

  let blob = new Blob(chunks, { 'type' : 'video/mp4;' });
            chunks = [];
            let videoURL = window.URL.createObjectURL(blob);
            vidSave.src = videoURL;

Apex:

 @AuraEnabled
    public static String save(String contactId, String srcVideo, string nameFile){
        System.debug('saveVideo');
        System.debug('contactId:: '+contactId);
        System.debug('srcVideo:: '+srcVideo);
        System.debug(' Blob.valueof(srcVideo): '+ Blob.valueof(srcVideo));
        System.debug('nameFile:: '+nameFile);
        try {
            ContentVersion conVer = new ContentVersion();
            conVer.ContentLocation = 'S'; // to use S specify this document is in Salesforce, to use E for external files
            conVer.PathOnClient =  'Test_Image.mp4';// The files name, extension is very important here which will help the file in preview.
            conVer.Title = nameFile; // Display name of the files
            conVer.VersionData = Blob.valueof(srcVideo);//EncodingUtil.base64Decode(srcVideo); // converting your binary string to Blog
            insert conVer;    //Insert ContentVersion
            System.debug('conVer: '+conVer);
            
            // First get the Content Document Id from ContentVersion Object
            Id conDoc = [SELECT ContentDocumentId FROM ContentVersion WHERE Id =:conVer.Id].ContentDocumentId;
            System.debug('conDoc:: '+conDoc);
            //create ContentDocumentLink  record 
            ContentDocumentLink conDocLink = New ContentDocumentLink();
            conDocLink.Visibility = 'AllUsers';
            conDocLink.LinkedEntityId = contactId; // Specify RECORD ID here i.e Any Object ID (Standard Object/Custom Object)
            conDocLink.ContentDocumentId = conDoc;  //ContentDocumentId Id from ContentVersion
            conDocLink.shareType = 'V';
            insert conDocLink;
            System.debug('conDocLink: '+conDocLink);
            
            
            // This doesn't execute since insert causes an exception
            System.debug('Statement after insert.');
            return 'true';
        } catch(DmlException e) {
            System.debug('The following exception has occurred: ' + e.getMessage());
            return String.valueOf(e.getMessage());
        }
    }
    

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.