zip files not downloaded on angular 13 although zip files created and api not give error ?
I work on application asp.net web api core 2.2 and angular 13 .
I make web api compress files and create it first as zip files .
then downloaded on my pc
compress file as zip extension correctly created .
issue done when download file on my pc
data response after finish
ERROR HttpErrorResponse {headers: HttpHeaders, status: 500, statusText: 'Internal Server Error', url: 'http://localhost:61265/api/Z2Delivery/ExportNormalizedRelation/', ok: false, …}
for more details see link below
File sharing and storage made simple[
^]
What I have tried:
what i try
on web api
[HttpPost, DisableRequestSizeLimit]
[Route("ExportNormalizedRelation")]
public IActionResult ExportNormalizedRelation()
{
return File(zipPath, "text/plain", Path.GetFileName(zipPath));
}
service angular
PostUploadzip(selectedoptionsId:Number, file:any):Observable<any>
{
const formData: FormData = new FormData();
formData.append('file', file,file.name);
formData.append('selectedoptions',selectedoptionsId.toString());
return this.http.post('http://localhost:61265/api/Z2Delivery/ExportNormalizedRelation/', formData,{responseType: 'blob'});
}
ts angular
public uploadFile = (selectedoptions:number) => {
this.selectedoptions= selectedoptions;
this.fileToUpload = this.selectedFiles.item(0);
this._dataService.PostUploadzip(this.selectedoptions,this.fileToUpload)
.subscribe((response: Blob) => saveAs(response, this.fileToUpload?.name + '.zip'));
}
html angular
<div class="row">
<div><button (click)="uploadFile(2)">Export Normalized Relation</button></div>
</div>