Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

210
Views
When I open a Salesforce Attachment it is downloaded but the pdf is empty

I am getting the attachment body using the Rest API.

var config = {
                method: 'get',
                url: '<Domanin>/services/data/v48.0/sobjects/Attachment/00PD000000HQD68MAH/Body',
                headers: {
                    'Authorization': `Bearer ${
                        accessToken
                    }`,
                    'content-type':'application/pdf'
                },
            };

       let rawData = await axios(config);
       rawData = rawData.data


I am getting the PDF data in this format

%PDF-1.5
%ÓôÌá
1 0 obj
<<

In the client side I am trying to make this as a downloadable file but I am getting blank pdf. The actual pdf contains 2 pages the downloaded pdf contains two pages as well but they are blank.

Client Side Code:

 var downloadLink = document.createElement('a');
            downloadLink.target = '_blank';
            downloadLink.download = 'test.pdf';

            // convert downloaded data to a Blob
            var blob = new Blob(([rawData]), {type: 'application/pdf'});

            // create an object URL from the Blob
            var downloadUrl = URL.createObjectURL(blob);

            // set object URL as the anchor's href
            downloadLink.href = downloadUrl;

            // append the anchor to document body
            document.body.append(downloadLink);

            // fire a click event on the anchor
            downloadLink.click();

Please let me know what is wrong with the above logic

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!