tsayen / dom-to-image

Generates an image from a DOM node using HTML5 canvas
Other
10.21k stars 1.68k forks source link

Have you ever seen these issues? why closed all about cors that not completed #430

Open ShinKyuJin opened 1 year ago

ShinKyuJin commented 1 year ago
const dataURLtoFile = (dataurl: string) => {
  const arr = dataurl.split(",");
  const bstr = atob(arr[1]);
  let n = bstr.length;
  const mime = arr[0].match(/:(.*?);/)![1];
  const u8arr = new Uint8Array(n);

  while (n--) {
    u8arr[n] = bstr.charCodeAt(n);
  }

  return new File([u8arr], "image.jpeg", { type: mime });
};

export const exportImage = async () => {
  const node = document.querySelector<HTMLElement>(".wrapper-quill");

  if (!node) return;

  const dataUrl = await domToImage.toJpeg(node, {
    quality: 1,
    cacheBust: true,
  });

  return dataURLtoFile(dataUrl);
};

https://github.com/tsayen/dom-to-image/issues/427 https://github.com/tsayen/dom-to-image/issues/315 https://github.com/tsayen/dom-to-image/issues/112 https://github.com/tsayen/dom-to-image/issues/29 https://github.com/tsayen/dom-to-image/issues/390

image

See my s3 bucket policy

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::asdfasfasdf/*"
        }
    ]
}
mohammad-matini commented 1 year ago

@ShinKyuJin You have to configure S3 to allow CORS for your specific domain. Please see the documentation at https://docs.aws.amazon.com/AmazonS3/latest/userguide/ManageCorsUsing.html and https://docs.aws.amazon.com/AmazonS3/latest/userguide/enabling-cors-examples.html