0

I have below code to add content document versionData into standard attachment.

    Map<Id, Blob> bodyContent = new Map<Id, Blob>();
    List<ContentVersion> contentDocs =  [SELECT Id, Description, title,versionData,ContentDocumentId FROM ContentVersion WHERE Id IN : contentIds];
    for(ContentVersion cVersion : contentDocs){
         bodyContent.put(cVersion.ContentDocumentId,cVersion.versionData);
    }

    for (ContentVersion attach : contentDocs) {
           Attachment conAttach = new Attachment();
           conAttach.ParentId = customAttach.Id;
           conAttach.Name = attach.title;
           conAttach.Body = bodyContent.get(attach.ContentDocumentId);
           conAttach.Description = attach.Id;
           attachmentListToInsert.add(conAttach);
    }

I have created the standard attachment with contentDocument versionData successfully. But when I download the attachment it is downloaded as type file.

enter image description here

But I want to download the file extension. Could anyone please help me to resolve this issue?

1
  • you probably need to append the FileExtension value to the filename, e.g. conAttach.Name = attach.Title + '.' + attach.FileExtension Commented Mar 31, 2019 at 18:49

1 Answer 1

0

How can I compose a multipart/form-data request?

Try like this.

Encode your contentversion data and convert as a blob

String strVersionData = EncodingUtil.base64Encode(cntver.VersionData);
Blob bBlob = EncodingUtil.base64Decode(strVersionData);
2
  • Hi Raja vel,, Thank you.. But still it is not working as expected. It downloaded as file type
    – JURY
    Commented Mar 7, 2019 at 6:36
  • get filetype like below...ContentDocument cntdoc = [Select Id,Title,OwnerId,ParentId,FileExtension,FileType,CreatedDate, ContentSize,CreatedById,LatestPublishedVersionId from ContentDocument where Id=:DocumentId]; Contentversion cntver = [select Id,VersionData,FileType from contentversion where Id=:cntdoc.LatestPublishedVersionId];
    – Raja vel
    Commented Mar 7, 2019 at 8:07

You must log in to answer this question.

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