I guess my back-end works, because this works and the zip is fine:
curl -X POST -H 'Content-Type: application/json' -d '{}' http://localhost:3000/zip/create > file.zip
My Django back-end returns the data like this:
return HttpResponse(data, content_type='application/octet-stream')
I cannot figure out what's wrong in my Angular 2 code, because the ZIP it gets ends up being somehow corrupted and I cannot open it.
The actual data seems to be in response._body
:
let blob = new Blob([response._body], { "type": 'application/octet-stream;' });
this.exportUrl = this.sanitizer.bypassSecurityTrustUrl(URL.createObjectURL(blob));
this.exportFileName = "download.zip";
After clicking that URL it downloads the zip but it doesn't work. So apparently I handle the binary data somehow incorrectly?
My service is essentially this:
return this.http.post(
this.zipUrl,
JSON.stringify(zipCreationParameters),
{headers: {'Content-Type': 'application/json'} });