Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

200
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda