lightgallery.js icon indicating copy to clipboard operation
lightgallery.js copied to clipboard

Improve download btn functionality

Open andimg93 opened this issue 2 years ago • 1 comments

Right now the download button only works for specific cases - Meta data (content-disposition) is related to an attachment, etc. .

Why not improving that functionality by just forcing the download based on the related image url, like:

fetch(url).then(res => res.blob()).then(file => {
    let tmpUrl = URL.createObjectURL(file);
    const aTag = document.createElement("a");
    aTag.href = tmpUrl;
    aTag.download = url.replace(/^.*[\\\/]/, '');
    document.body.appendChild(aTag);
    aTag.click();
    URL.revokeObjectURL(tmpUrl);
    aTag.remove();
}).catch(() => {
    alert("Failed to download file!");
});

Something like that will always work, so also for an image url like this one: Test image

https://cdn.savepaper.work/test.jpg

andimg93 avatar Sep 01 '22 04:09 andimg93

See #226 - still an open task.

andimg93 avatar Sep 01 '22 04:09 andimg93

This issue has been automatically marked as stale because it has not had recent activity. If the issue is still valid for version 2.x, please re-open. Apologize for not responding on time. Thank you for your contributions.

stale[bot] avatar Oct 02 '22 00:10 stale[bot]

Still an issue @andimg93

tarikhaiga avatar Nov 13 '22 01:11 tarikhaiga