[SalesForce] Upload a file via Apex

How can i upload a file from my client PC via Apex ? I need it for a test class so i cannot make api callout.
I try this but without success

String yourFiles = 'Lets assume this is your binary string of the files';

ContentVersion conVer = new ContentVersion();
conVer.ContentLocation = 'E'; // S specify this document is in SF, use E for external files
conVer.PathOnClient = 'C:\myPC\Accounts1472.csv'; // The files name, extension is very important here which will help the file in preview.
conVer.Title = 'Accounts1472 '; // Display name of the files
conVer.VersionData = EncodingUtil.base64Decode(yourFiles); // converting your binary string to Blog
insert conVer;

Any suggestions please ?

Best Answer

I solved the issue by doing the following: 1) Get to https://onlinecsvtools.com/convert-csv-to-base64 and convert the content of my CSV 2) Since i did not find solution to insert directly from my client pc i used the Salesforce ContentLocation but i inserted my content.

String yourFiles = 'RUFfQ/Om86XIM6kzpgxMTMJzqHOn86Uzp==';

        ContentVersion conVer = new ContentVersion();
        conVer.ContentLocation = 'S'; // S specify this document is in SF, use E for external files
        conVer.PathOnClient = 'ionicLogo.csv'; // The files name, extension is very important here which will help the file in preview.
        conVer.Title = 'Accounts '; // Display name of the files
        conVer.VersionData = EncodingUtil.base64Decode(yourFiles); // converting your binary string to Blog
        insert conVer;

        // First get the content document Id from ContentVersion
        Id conDoc = [SELECT ContentDocumentId FROM ContentVersion WHERE Id =:conVer.Id].ContentDocumentId;

        //Create ContentDocumentLink
        ContentDocumentLink cDe = new ContentDocumentLink();
        cDe.ContentDocumentId = conDoc;
        cDe.LinkedEntityId = batch.Id; // you can use objectId,GroupId etc
        cDe.ShareType = 'I'; // Inferred permission, checkout description of ContentDocumentLink object for more details
        cDe.Visibility = 'AllUsers';
        insert cDe;