My current challenge involves receiving a multipart/mixed
response over HTTP that includes JSON data and PDFs in byte format. Due to Angular's limitations with handling such responses, I have resorted to converting the response into a string using the responseType: 'text'
option.
To work with this data, I break down the response, extract the JSON, and transform the PDF data into a Blob as shown below:
let pdf: Blob = new Blob([new TextEncoder().encode(bytestring)], { type: 'application/pdf' });
The issue arises when attempting to create a download link for the PDF using window.URL.createObjectURL(pdf)
, resulting in a damaged file that cannot be opened.
I have verified that Angular utilizes UTF-8 encoding when turning the response into a string. Additionally, setting up a separate route allows me to request a single PDF independently with responseType: 'blob'
which successfully downloads a functional PDF. Comparison between the original PDF and the damaged one at a byte level in VS Code reveals no noticeable differences.
Given my ability to transfer a working PDF separately but facing challenges within the multipart request, it appears that the conversion of a PDF to a string and back may be causing issues. Is there a solution that avoids transforming the PDF into a string?