1

I have a site, containing only an image in the center of it. When somebody clicks it, image begins downloading to the user's computer. Recently, i've tried to launch it as Telegram Web App and there happend to be a problem. When i click the image on my pc (as TG WebApp) everything works properly, but when clicking it on my phone (sumsung a51) (as TG WebApp) nothing happens. Code of my site: HTML (only body):

<div class="wrapper">
    <img class="image" src="pathtoimg" alt="img"></img>
</div>
<script src="https://telegram.org/js/telegram-web-app.js"></script>
<script src="./index.js"></script>

JS (index.js):

async function toDataURL(url) {
    const blob = await fetch(url).then(res => res.blob());
    return URL.createObjectURL(blob);
}

async function downloadFile(src, filename) {
    const a = document.createElement("a");
    a.href = await toDataURL(src);
    a.download = filename;
    document.body.appendChild(a);
    a.click();
    document.body.removeChild(a);
}

function main() {
    const image = document.querySelector(".image")
    if (image) {
        image.addEventListener("click", (e) => {
            downloadFile(image.src, "image.png")
        })
    }
}

main()

Thank to everybody trying to help me, i value it

1 Answers1

-1

I am not sure this will work in Telegram Web Apps for now. In mobile browsers, you have to confirm file download. This should work the same with Web Apps, but currently, it is not implemented. Good feature idea.

  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/33391204) – chrslg Dec 16 '22 at 10:29
  • @chrslg As follows from my answer - *this functionality is not implemented in Telegram Web Apps*. It means, your code will not work. Seems rather obvious – Vladislav Kibenko Dec 18 '22 at 00:28