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

405
Vistas
when recieving a file as a FileContentResult through an ajax post request, the byte array seems to get corrupted when passed into the response

I'm using ajax to generate and view a File.

$.ajax({
    url: '/Materials/Enquiries/GetRequisitionVersion',
    type: 'POST',
    data: $('#materialRequisitionVersionForm').serializeArray()
}).done(function (response) {
    var file = new Blob([response], { type: 'application/pdf' });
    var fileURL = URL.createObjectURL(file);
    window.open(fileURL);

}).fail(function () {

})

This is my controller method. The GenerateMaterialRequisitionPreview function returns a byte Array. To test I created a filestream to save the file locally.

public async Task<IActionResult> GetRequisitionVersion(Guid requisitionId)
    {
        var bytes = await _reportingClient.GenerateMaterialRequisitionPreview(requisitionId);
        
        //For testing
        using (FileStream pdfOutput = new FileStream("test2.pdf", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite))
        {
            pdfOutput.Write(bytes);
        }
            return File(bytes, "application/pdf", "generated.pdf");
    }

In the ajax response, when the new window opens, it returns an empty PDF file , however when i check the file saved by the filestream it's correct. generated.pdf test2.pdf

I inspected both pdf arrays and found that some of the characters in the generated pdf have been replaced by unknown characters □ and � If you compare these two images you'll see what i mean. corruptedPDF correctPDF

I'm not exaclty sure why the file is being corrupted this way and a fix for this. I am using google chrome.

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