function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rakshana Cube84Rakshana Cube84 

How to compress the contentdocument in apex code itself

Hi All,
Is there any way to compress a blob file before inserting into contentversion and contentdocumentlink. Because my file storage is very low let me know the price details of the file storage space in Salesforce.

Raj VakatiRaj Vakati
Try this code

base64Data = EncodingUtil.urlDecode(base64Data, 'UTF-8');
        ContentVersion cv = new ContentVersion();
        cv.ContentLocation = 'S';
        cv.ContentDocumentId = contentDocumentId;
        cv.VersionData = EncodingUtil.base64Decode(base64Data);
        cv.Title = fileName;
        cv.PathOnClient = filename;
        insert cv;
        //***This DEBUG statement must return an Id for the rest of the code to work***
        ContentDocumentLink cdl = new ContentDocumentLink();
        cdl.ContentDocumentId = cv.ContentDocumentId;
        cdl.LinkedEntityId = parentId;
        cdl.ShareType = 'I';
        insert cdl;