Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

408
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda