i want to convert my cropped canvas to file,this is my code in order to do that:
const canvas = previewCanvasRef.current;
canvas?.toBlob((blob) => {
const file = new File([blob], 'fileName.jpg', { type: 'image/jpeg' });
}
but when i try to do that i get this error message:
Uncaught SecurityError: Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported
i've done some reasearch and find out the root of problem is img cross origin, since i get img data from url, so i changed it to
<img crossorigin="anonymous" />
but after that, i get different error message that is:
has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
what can i do in order to solve this problem?