sachinchoolur / lightgallery.js

Full featured JavaScript image & video gallery. No dependencies
https://sachinchoolur.github.io/lightgallery.js/
Other
5.3k stars 596 forks source link

Improve download btn functionality #227

Closed andimg93 closed 2 years ago

andimg93 commented 2 years ago

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 commented 2 years ago

See #226 - still an open task.

stale[bot] commented 2 years ago

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.

tarikhaiga commented 1 year ago

Still an issue @andimg93