I get my test image in files, but can't to see the preview. How can I fix that?

public static void save(String resumeId, String versionData){ 
        ContentVersion currentContentVersion = new ContentVersion(
            Title = 'test',
            PathOnClient = 'test',
            VersionData = EncodingUtil.base64Decode(versionData),
            FirstPublishLocationId = resumeId
        insert currentContentVersion;


handleFileSelected: function(component, event, helper) {
    let files = event.getParam("files");
    let file = files[0];

    let action = component.get("c.save");
    var fr = new FileReader();

    fr.onload = function() {
        var fileContents = fr.result;
        var base64Mark = 'base64,';
        var dataStart = fileContents.indexOf(base64Mark) + base64Mark.length;

        fileContents = fileContents.substring(dataStart);

            resumeId : 'a01f400000Nx9vgAAB',
            versionData : fileContents


1 Answer 1


Start by querying in the developerConsole using something like the following:

SELECT id, ContentDocumentId, FileExtension, FileType FROM ContentVersion... 

If the contentVersions you are uploading are missing FileExtension and FileType, it's likely that your path information, which is how FileExtension and FileType are derived is incorrect (I've seen uploaded example code for ContentVersion with a value like 'email' in this field, which will prevent preview from working).

Change path on client from 'test' to somethinng like the following, including the extension in the filename:

PathOnClient = '/' + fileName;

It looks like you have encoding set correctly. If anyone else has trouble with saving an attachment from an email, another step to try to is to set VersionData as follows:

VersionData = EncodingUtil.base64Decode(theAttachment.body);'
  • +1 for the PathOnClient hint. Thas was something that has eluded me for a while during debugging. Commented May 24, 2020 at 17:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .