I have a code to convert image to dataUrl
convertToDataURLviaCanvas(url, outputFormat){
return new Promise((resolve, reject) => {
const img = new Image();
img.crossOrigin = 'anonymous';
img.onload = () => {
let canvas = <HTMLCanvasElement> document.createElement('CANVAS'),
ctx = canvas.getContext('2d'),
dataURL;
canvas.height = img.height;
canvas.width = img.width;
ctx.drawImage(img, 0, 0);
dataURL = canvas.toDataURL(outputFormat);
resolve(dataURL);
canvas = null;
};
img.src = url;
});
}
and a call this function
this.convertToDataURLviaCanvas('https://www.google.de/images/srpr/logo11w.png', 'image/jpeg').then(imageData => {
this.zip.file(image.file_name, imageData, {binary: true})
this.zip.generateAsync({type: 'blob'}).then(content => {
saveAs(content, 'images.zip');
});
})
but there's an error with CORS
Failed to load https://www.google.de/images/srpr/logo11w.png: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access.
how can I fix it