react-modal-image icon indicating copy to clipboard operation
react-modal-image copied to clipboard

when i click download image, the image is opened in new tab

Open JasirMJ opened this issue 5 years ago • 11 comments

JasirMJ avatar Apr 11 '20 12:04 JasirMJ

@JasirMJ would you elaborate this. What browser are you using? Are you clicking the download-icon on the top right corner? I'm unable to reproduce this issue with the latest Chrome, Edge, Safari and Firefox.

aautio avatar Jun 12 '20 15:06 aautio

I tryed on chrome and mozilla, Not able to download image in single click. Instead of downloading them image is open in another tab,

My backend server is hosted on Aws And Frontend is hosted on firebase

Image is loaded from backend server to client

JasirMJ avatar Jun 22 '20 09:06 JasirMJ

Hi there, Same issue here - in my case my App is here - http://4x4pb.chapterserver2.co.uk/ - if you click an image of a wheel, lightbox shows but download button does not download the image, simply opens the image in the SAME tab. Download attribute is definitely on the link. My images are on a seperate domain (same server) in a WordPress uploads directory.

Any thoughts?

thelar avatar Jul 28 '20 09:07 thelar

Apologies... I have now realised that my issue is because the image is on a different domain and that the download attribute only works correctly when on the SAME domain. I'm now using axios to asyncronously get a blob of the image and using that as my large - works fine!

thelar avatar Jul 28 '20 11:07 thelar

Nice discovery! I did not know that the download only works when on the same domain. This will help to find a solution for the issue.

aautio avatar Jul 28 '20 11:07 aautio

@aautio, thanks for this lib!

Could you maybe implement a "onClickDownload" param, so we can handle this "cors images download" issue?

Right now, my work around looks like this:

const ModalImageCors = ({ imageUrl }) => {
	const [fetching, setFetching] = useState(false);
	const [url, setUrl] = useState("");

	useEffect(() => {
		setFetching(true);
		if (!imageUrl) return;
		const fetchImage = async () => {
			const res = await api.get(imageUrl, { responseType: "blob" });
			const blobUrl = window.URL.createObjectURL(
				new Blob([res.data], { type: res.headers["content-type"] })
			);
			setUrl(blobUrl);
			setFetching(false);
		};
		fetchImage();
	}, [imageUrl]);

	if (fetching) return null;

	return (
		<ModalImage
			smallSrcSet={url}
			medium={url}
			large={url}
			alt="image"
		/>
	);
};

export default ModalImageCors;

It would be nice if I could put this "turn image into blob" logic on a function and call it when users click "Download" on Modal Image.

Thanks anyway!

canove avatar Oct 05 '20 22:10 canove

Hi, @aautio are you still supporting this lib? Did I saw no updates in a year, could be the @canove suggestion implemented?

rootlinux2 avatar Oct 19 '20 17:10 rootlinux2

@rootlinux2 yep still supporting this. I haven't yet studied this issue - I guess the blob-approach could work. I'll need to test it first - perhaps later this week.

aautio avatar Oct 19 '20 20:10 aautio

@aautio thanks, great news! I just clone the repo to see if I can help with any of these issues.

rootlinux2 avatar Oct 20 '20 00:10 rootlinux2

how about if u wanted to title and paragraph with an external link >?

simondodson avatar Nov 16 '20 17:11 simondodson

hello, i have the same problem. Has anyone managed to solve it?

inforeis avatar Apr 08 '21 23:04 inforeis

Sorry for the long wait! A fix is ready for these cross-origin / external domain issues. I'll publish the next version 2.6.0 in a few days once I've fixed a couple of additional issues.

You can try to click the download-icon on the bottom image at https://aautio.github.io/react-modal-image/ It uses fetch to circumvent same-origin requirements of download attribute. I've tested it on Chrome, Firefox and Safari and it seems to work.

aautio avatar Sep 08 '22 14:09 aautio