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

198
Vistas
Append PDF binary string to JS FormData
var uploadData = new FormData();
uploadData.append('myFile', pdfData, fileName);

pdfData is coming from another server and outputs following on the console (excerpt):

%PDF-1.3 %¿÷¢þ 1 0 obj << /Metadata 3 0 R /Pages 4 0 R /Type /Catalog >> endobj 2 0 obj

so it's a PDF file in binary string (?).

Executing this code leads to following exception:

Uncaught TypeError: Failed to execute 'append' on 'FormData': parameter 2 is not of type 'Blob'.

When trying this:

uploadData.append('myFile', new Blob([pdfData], {type: 'application/pdf'}, fileName);

the request goes through but I get errors on the server side:

java.io.IOException: java.util.zip.DataFormatException: invalid code lengths set

So the PDF is sent not correctly, I assume.

How to encode pdfData correctly?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

check if your Blob instance contains a valid PDF file. Like this:

const blob = new Blob([data], { type: file.mime_type });
const blob_url = URL.createObjectURL(blob);

and then create an element to view it:

const embed_element = document.createElement('embed');
embed_element.setAttribute('src', blob_url);
embed_element.setAttribute('width', '800px');
embed_element.setAttribute('height', '2100px');
document.body.append(embed_element);

Does it show the PDF file correctly?

You should also check in your developer tools if the request is sent correctly. I think it should look similar to this (raw FormData in Chrome):

enter image description here

about 4 years ago · Juan Pablo Isaza Denunciar
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