Closed souramoo closed 1 month ago
Can you provide a reproduce demo to let me know the CORS problem?
Sure!
https://codepen.io/souramoo/pen/PorVvrQ
the first link has a download button labelled 'dl' which does not work, while the other images do.
In this article, it has giving a solution for cross origin image.
https://www.hacksoft.io/blog/handle-images-cors-error-in-chrome#solution
fetch(ctx.images[ctx.index].src + "?not-from-cache-please")
.then((res) => res.blob())
.then((blob) => {
fileSaver.saveAs(blob, 'image')
});
Unfortunately this does not work for all URLs - especially signed URLs where the image is hosted in AWS/GCP/Azure and any changes to the URL will invalidate the URL. My use case is displaying images with a download button loaded from signed AWS S3 URLs to enforce authentication.
This PR fixes it for all URLs without requiring resigning of the URL from the server (which is not always possible).
Unfortunately this does not work for all URLs - especially signed URLs where the image is hosted in AWS/GCP/Azure and any changes to the URL will invalidate the URL.
This PR fixes it for all URLs without requiring resigning of the URL from the server (which is not always possible).
So I hope you can give me an image URL to test. I think if the plugin can load cross origin image, you can also fetch it by yourself.
Have updated the codepen with a test URL.
https://codepen.io/souramoo/pen/PorVvrQ
The image URL is:
This URL if changed will no longer work. If fetching it to download it after the browser has already displayed the image, will also no longer work in chromium as the URL has been tainted.
Test with 3.10.2
and the image can't display. https://codepen.io/nzbin/pen/zYVbYEB
Then test with 3.10.0
and the image can be downloaded. I don't know why...
PR #54 fixed an issue but caused issue #56 - to fix #56, #54 was reverted. This PR fixes both by making the crossorigin optional and disabled by default - the behaviour of chromium on image loading is complex and hopefully by being flexible this fixes the issue for good!