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
Rajesh_ShahRajesh_Shah 

File Preview Issue

I have an application through which I allow users to upload file or paste data in Text Area which I then upload as an attachment. These attachment then also used for creating or updating the Content File related to the Contact. 

 

When the file is uploaded, the preview in the content comes fine. However, when I paste the content of the file in Text area, and when the Content feed is created or updated, the preview doesn't come. Has anybody faced this issue before? Also attaching the code for the same:

 

// Inserting attachment
Resume.Body = Blob.valueOf(ResumeText);
Resume.ContentType = 'application/msword';
Resume.ParentId = contactId;
insert resume;

// Insert/Update Content
cdl = [SELECT ContentDocumentId 
                       FROM ContentDocumentLink 
                       WHERE LinkedEntityId = :Resume.ParentId 
                       ORDER BY SystemModstamp          
                       limit 1];
ContentVersion cv = new ContentVersion();
cv.ContentDocumentId = cdl.ContentDocumentId;
cv.VersionData = Resume.Body;
cv.PathOnClient = Resume.Name;                  
insert cv;

 

Jia HuJia Hu
The VersionData should be base64 format.

It is not the problem of the preview, if you download the file, can you open it as what you wanted?
Rajesh_ShahRajesh_Shah

Even while opening, it first ask what application do I want to use for viewing this file. After I select MS Word, the file comes out fine.

 

How do I give base64 format to the body?

 

 

Jia HuJia Hu

Blob ablob = EncodingUtil.base64Decode('string');

But it does not work.

I guess we can't create a real Word format by just simply set
ting the format as Word.