I am employing the ngx-uploader npm module in my angular single page application.
In an angular component, I am using the ngx-uploader module to upload a file to my server endpoint. The server processes the data and returns binary data -- zip file content.
The below typescript code is executed when the http response is received from the server -- the 'done' case.
The output object contains response data in the 'output.file.response' property.
But when I save the data to a zip file, the zip file contains data that is CORRUPTED.
Has the 'output.file.response' been altered in some way (e.g. converted binary to string)?
What do I need to do to properly create a Blob object from the response?
case 'done':
this.inProgress = false;
const zipData = output.file?.response;
const blobOptions: BlobPropertyBag = {
type: 'application/zip'
};
const zipFileContent = new Blob(
[ zipData ],
blobOptions
);
const zipFileName = 'zip-file.zip';
FileSaver.saveAs(
zipFileContent,
zipFileName
);
break;
2023-01-02 Follow up:
I see that at:
This code is being used:
try {
file.response = JSON.parse(xhr.response);
} catch (e) {
file.response = xhr.response;
}
It appears that the catch block is not applied and the binary response is being corrupted. I don't see any way to workaround. Looks like I will have to find another module.