0

I'm tried to insert contentversion record from API response. In response getting PDF only. I've tried below code but i'm having issue in previewing the file.

ContentVersion cv = new ContentVersion();
blob image = response.getBodyAsBlob();
cv.VersionData = image;
cv.PathOnClient = Sample; 
cv.title = Sample; 
cv.origin = 'H';
insert cv;

Same response I tried to insert as Attachment. Its working fine.

Attachment objAttachment = new Attachment();
objAttachment.Body =  response.getBodyAsBlob(); 
objAttachment.ParentId = '132435454';
objAttachment.Name = 'Test';
objAttachment.ContentType = 'application/pdf';
insert objAttachment;

Please advise me what I missed in ContentVersion.

1 Answer 1

1

You have skipped the extension part in Contentversion. You need to give file title name with extension.

cv.title = Sample+'.pdf'; 

ContentVersion

2
  • Thanks for reply. We have add to cv.PathOnClient = Sample+'.pdf'; then only its work without issue.
    – user10286
    Feb 21, 2018 at 3:50
  • @user10286 then you can accept the answer and close the question. Feb 21, 2018 at 14:18

You must log in to answer this question.

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