Currently I'm using Angular5Csv and can already download CSV file normally.
But now my client want to download it as Zip file type. I did tried some methods and can download it as Zip file type, but can't unzip it.
Below is my code:
downloadLog(hall_id: String, from_date: Date, to_date: Date) {
let params = new HttpParams();
params = hall_id ? params.append('hall_id', hall_id.toString()) : params;
params = from_date ? params.append('from_date', from_date.toString()) : params;
params = to_date ? params.append('to_date', to_date.toString()) : params;
return this.http
.get(`${this.apiLog}`, {params: params})
.pipe(
tap((response: any) => {
var options = {
fieldSeparator: ',',
quoteStrings: '"',
decimalseparator: '.',
showLabels: true,
useBom: true,
noDownload: true,
headers: ['id', 'delete_flag', 'hall_id', 'send_type', 'type', 'reply_token'
, 'source_type', 'source_id', 'message_id', 'message_type', 'text', 'title', 'address', 'latitude'
, 'longitude', 'package_id', 'sticker_id', 'data', 'timestamp', 'created_date', 'updated_date'
, 'deleted_at']
};
this._csv = new Angular5Csv(response.data, 'Log Messages', options);
const blob = new Blob([this._csv['csv']], {
type: 'application/zip'
});
const url = window.URL.createObjectURL(blob);
window.open(url);
// this.log('Download successfully。', 'success', true);
}),
catchError(this.handleError('downloadLog', {success: false}))
)
.subscribe(res => {
}, error => {
}, () => {
});
}
I'm new to Angular and don't know much about it. It would helped me a lot if I could receive some help. Thanks