Hello Stack Overflow community,
I am developing a Telegram Mini App using React JS and encountering an issue with downloading images directly from the frontend. I have an image stored locally in my project’s assets and I want to provide a feature that allows users to download this image directly onto their devices while using the Telegram Mini App.
Here’s what I’ve tried:
Implementing an tag with the download attribute, triggered by a button click.
Using JavaScript to dynamically create a link and simulate a click for downloading.
Example:
const handleDownloadClick = (event) => {
event.preventDefault();
const link = document.createElement('a');
link.href = img;
link.download = title || 'download';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
};
However, neither method is triggering a download in the Telegram Mini App’s built-in browser. Instead, it either does nothing or opens the image in a new tab without downloading.
Is there a known limitation or security policy in Telegram Mini Apps that prevents direct downloads? Or is there a specific method or workaround that can be used to enable file downloads within this environment?
Thank you for any insights or suggestions you can provide!
Alexander Pop is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.