Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i work on web page web api and angular 11

this page take input file excel and get result on excel file as output

i get error i don't know what is the reason of error and how to solve it

error as below

Access to XMLHttpRequest at 'https://pn.xxx.com:7072/api/Z2Delivery/ExportNxp' from origin 'https://pn.xxx.com:7071' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
:7072/api/Z2Delivery/ExportNxp:1 
 Failed to load resource: net::ERR_FAILED
main.f13cbf3….js:1 ERROR 
e {headers: n, status: 0, statusText: 'Unknown Error', url: 'https://pn.xxx.com:7072/api/Z2Delivery/ExportNxp', ok: false, …}
error: ProgressEvent {isTrusted: true, lengthComputable: false, loaded: 0, total: 0, type: 'error', …}
headers: n {normalizedNames: Map(0), lazyUpdate: null, headers: Map(0)}
message: "Http failure response for https://pn.xxx.com:7072/api/Z2Delivery/ExportNxp: 0 Unknown Error"
name: "HttpErrorResponse"
ok: false
status: 0
statusText: "Unknown Error"
url: "https://pn.xxx.com:7072/api/Z2Delivery/ExportNxp"
[[Prototype]]: Object


so please can any one help me please ?

What I have tried:

web api
[Route("ExportNxp")]
        public IActionResult ExportNxp(bool areIdentical)
        {
         
                if (areIdentical == false)
                {
                    return OK("Not Matched Excel");
                }
                else  
                {
                   
                return PhysicalFile(zipPath, "application/zip", Path.GetFileName(zipPath));
              
                }

        }
service.ts
PostUploadzipNxp(file:any):Observable<any>
{
  formData.append('file', file,file.name);
  return this.http.post('https://pn.xxx.com:7072/api/Z2Delivery/ExportNxp/', formData,{observe: 'response', responseType: 'blob' });
}
component.ts
 this._dataService.PostUploadzipNxp(this.fileToUpload)
     .subscribe(blob => {
       saveAs(blob.body, this.fileToUpload?.name +'.zip');
      });
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900