While attempting to convert an image URL to Base64 using the FromImageUrl method, I encountered an error in my console.
Access to the image located at '' from the origin 'http://localhost:8383' has been blocked due to CORS policy: The 'Access-Control-Allow-Origin' header is missing from the requested resource. As a result, the origin 'http://localhost:8383' is denied access.
Here is my JavaScript code:
function getBase64FromImageUrl(url) {
var img = new Image();
img.setAttribute('crossOrigin', 'Access-Control-Allow-Origin', 'anonymous');
img.onload = function () {
var canvas = document.createElement("canvas");
canvas.width = this.width;
canvas.height = this.height;
var ctx = canvas.getContext("2d");
ctx.drawImage(this, 0, 0);
$scope.a = canvas.toDataURL("image/png");
};
img.src = url;
}
getBase64FromImageUrl("http://160.114.10.19/voiceapi/Upload/UserProfile/b4d980b3-3e8e-4e26-913e-e79e4ce34f88.png");