0

enter image description here

When I download my picture, it is an error:No 'Access-Control-Allow-Origin' header is present on the requested resource. codes of download pictures:

export function downloadPhoto (imgsrc) {
  let image = new Image();
  image.setAttribute("crossOrigin", "anonymous");
  image.onload = function() {
    let canvas = document.createElement("canvas");
    canvas.width = image.width;
    canvas.height = image.height;
    let context = canvas.getContext("2d");
    context.drawImage(image, 0, 0, image.width, image.height);
    let url = canvas.toDataURL("image/png");
    let a = document.createElement("a");
    let event = new MouseEvent("click");
    a.download = "photo";
    a.href = url;
    a.dispatchEvent(event);
  };
  image.src = imgsrc;
}
Chestnut
  • 3
  • 1
  • it's up to the server you're getting the image from to allow cross origin or not - read [docs](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#attr-crossorigin) – Bravo Aug 27 '21 at 02:27
  • I think it is about [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) – YuTing Aug 27 '21 at 02:28

0 Answers0