I can't seem to set a zip file's name from a web API in a HttpResponseMessage
. I can successfully create the zip file using ZipArchive with all its content files, but when downloading it from client side (although it does return and open successfully) the name appears in a 16-byte hexadecimal format like a guid. I would like to set a custom name for my zip file. Where should I do this?
Setting the ContentDisposition
doesn't work:
responseMessage.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
{
FileName = attachmentName
};
From the client side using Angular2+ I return the file as a blob:
DownloadAtachment(url: string): Observable<Blob> {
const requestHeaders = new Headers(
{
'Content-Type', 'application/json',
'Accept', 'application/zip'
},
);
let options = new RequestOptions({ headers: requestHeaders });
let args: RequestOptionsArgs = {headers: options, withCredentials:false, responseType: ResponseContentType.ArrayBuffer};
return this._http.get(url, args)
.map(response => {
return new Blob([response.blob()], { type: 'application/zip'});
});
}