I am making a callout from custom button on a record to the document management system(client) which has attachments.When I request from custom button I do two things:

1.Requesting by doing callout to DMS client and getting response as binary.

2.It's redirecting to vf page for viewing the response received from DMS as binary(client).

It's basically not storing any attachments in SFDC rather it is showing/viewing attachment from DMS client whenever I request.Client DMS has provided me their wsdl I have parsed and I am also getting response as binary, after that I am converting it to blob and wanted to display on VF page or somewhere else where end user can view/download it.But unable to do that.

Please find the code below:

Visualforce Page:

<apex:page showHeader="false" sidebar="false" controller="AttachmentBodyController" contentType="{!attachment.ContentType}#{!attachment.Name}">


public with sharing class AttachmentBodyController {

    public String body {get; set;}
    public Attachment attachment {get; set;}
    public AttachmentBodyController() {
        String Id  = ApexPages.currentPage().getParameters().get('id');
        attachment =  [SELECT Id, Name, Body, ContentType FROM Attachment WHERE Id = :Id];
        body = EncodingUtil.base64Encode(attachment.body);

It downloads but file is corrupted? How to resolve this error?

  • 1
    I think you can store this data as an attachment and redirect user to the attachment link to download it. Render Blob on VF – manjit5190 Jan 24 '17 at 9:33
  • thanks for the response but the challenge is I don't want to store attachment in SFDC.Do you know any other way?? – Salesforce Learner Jan 24 '17 at 9:35
  • Can you paste the file content. I think you are downloading the base64, no the bytes – Edu Trujillo Oct 20 '17 at 5:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.