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

406
Views
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
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!