I get a CORS error when I'm trying to download and use a Cloudinary widget javascript resource with the Angular HttpClient.
What is going on? I'm not new to HttpClient or CORS but have never seen this.
Access to XMLHttpRequest at 'https://widget.cloudinary.com/v2.0/global/all.js' from origin 'http://127.0.0.1:4200' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
The server CORS has nothing to do with this question. It is publicly available code and can easily be retrieved in any browser.
The requested script does arrive in my Chrome Dev Tools / Network tab XHR section. So the server sent it and Chrome happily received it.
I'm in the Angular dev environment.
The problem is with Angular and I think HttpClient. It thinks there is a CORS issue that doesn't exist.
Request headers in Dev Tools: Sec-Fetch-Mode: cors
I've looked at a bunch of other SO posts, including one that appears to be similar, but no help.
My code.
export class CloudinaryComponent implements OnInit {
private url = 'https://widget.cloudinary.com/v2.0/global/all.js';
constructor(
private http: HttpClient
) {}
ngOnInit() {
this.loadWidget;
}
// Load the Cloudinary Upload Widget code, not the widget GUI.
private loadWidget() {
return this.http.get(this.url);
};
// Button click calls the Upload Widget GUI.
private callPopup() {
this.loadWidget().subscribe( result => {
// this.uploadWidget.open();
});
}
}
How can I embed the Cloudinary widget properly?