ahmed elbarbary

ahmed elbarbary

  • NA
  • 1.6k
  • 275.3k

File not downloaded as attachement on browser although api return file

Nov 24 2020 6:03 AM
I work on asp.net core 2.2 web api project with angular 7 .
my issue on when click on upload button
 
File not download as attachment on browser .
 
when put break point on api and run angular app it hitted break point and file name can see from api when pass it
 
I think this is problem of angular 7 because web api return file  
 
on angular 7 
  1. on angular 7  
  2.    
  3. component.ts    
  4.   fileToUpload: File = null;    
  5.   public uploadFile = (files) => {    
  6.          
  7.     const formData = new FormData();    
  8.         
  9.     formData.append('file', this.fileToUpload,this.fileToUpload.name);    
  10.      
  11.   this.http.post('https://localhost:44396/api/ApprovalQuality/', formData)    
  12.     
  13.       .subscribe(data =>{    
  14.                
  15.       }, error => {      
  16.         console.log(error);      
  17.       });    
  18.      
  19.   }    
  20. handleFileInput(files: FileList) {    
  21.     if (files.length == 0) {    
  22.         return;    
  23.       }      
  24.     this.fileToUpload = files.item(0);    
  25.     console.log(this.fileToUpload)      
  26. }    
  27.     
  28. component.html    
  29.  <button type="button" class="btn btn-success" (click)="uploadFile(files)">Upload Filebutton>    
 
test api return like that by post man give me 200 Status OK
 
but on browser no file download as result
 
when connect angular 7 with api no file returned and no file downloaded
 
so How to solve issue
 
 

Answers (2)