const executeSaveAs = (content) => {
let blob = new Blob([content], {'type': "application/octet-stream"});
saveAs(blob, "downloaded_zip.zip"); // This is from https://github.com/eligrey/FileSaver.js
};
return this.http.get(url, {responseType: 'arraybuffer'}).pipe(executeSaveAs);
We need to set the expected type of response we want to be "arraybuffer". Then we make the usual material for FileSaver, which creates a blob and passes it to a batch function saveAs.
Edit
In accordance with the commentary, it turned out that to parse the various parts of the multi-part answer, it was clarified.
Multipage Content Type Information
, , .
--boundaryThatIsInTheHeader
. . RegEx :
let boundaryRegex = new RegExp(/boundary=(\S+)/g);
const header = `Content-Disposition:attachment; filename="Config.zip" Content-Type:multipart/mixed;boundary=Boundary_25_1816124633_1519993185650 MIME-Version:1.0 Transfer-Encoding:chunked`;
const boundary = '--' + boundaryRegex.exec(header)[1];
.
response.split(boundary);
, ,
[ "", " Content-Type: application/json\n\n {\"config\":[{},{},{}]} ", " Content-Type: application/octet-stream\n\n PKMÛJAä;%RecurrenceEvent_CreateContract_1.jsoníYKoãF¾ÈxÝ0è÷Ã7Mb L&íÝK0ͦCD¬1ðß(J¤HÙ²¼yV'»ÙU¬®úªú«â· ö«åºv~Í~ùöýw³Ù,È«ù"]
, JSON. , ! , .. , RegEx. , . zip .