Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cross-domain download #95

Open
GHNature opened this issue Oct 26, 2022 · 5 comments
Open

cross-domain download #95

GHNature opened this issue Oct 26, 2022 · 5 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@GHNature
Copy link

Download cross-domain image resources, click download will open a new tab, can it start downloading directly after clicking the button

@arnowelzel
Copy link
Owner

I am sorry, but I do not understand exactly what the issue is about. There is no "download" to click in PhotoSwipe 5, so this would first have to be added. Do you want to have a "download" option for PhotoSwipe 5 as well?

Furthermore - what means "will open a new tab, can it start downloading directly after clicking the button". What should be in the new tab and what button are you talking about?

And finally - what has "cross-domain" to do with that all? The download option in PhotoSwipe 4 works regardless from which domain the image is being used from - however it will just link directly to the image. What the browser will do with the image can not be changed by PhotoSwipe, that only depends on what the server will send to the browser.

@GHNature
Copy link
Author

I am sorry, but I do not understand exactly what the issue is about. There is no "download" to click in PhotoSwipe 5, so this would first have to be added. Do you want to have a "download" option for PhotoSwipe 5 as well?

Furthermore - what means "will open a new tab, can it start downloading directly after clicking the button". What should be in the new tab and what button are you talking about?

And finally - what has "cross-domain" to do with that all? The download option in PhotoSwipe 4 works regardless from which domain the image is being used from - however it will just link directly to the image. What the browser will do with the image can not be changed by PhotoSwipe, that only depends on what the server will send to the browser.

Since I wanted it to show a download button, I switched to Phtoswipe 4, and when I clicked the download button, the browser didn't download the image directly, but reopened a tab to display the image. I searched and found out that it is because the download attribute of the A tag is only applicable to the case of the same origin of the domain name. I opened your Demo Site in Chrome and it also opened a new tab to display the image.

@arnowelzel
Copy link
Owner

arnowelzel commented Oct 27, 2022

Since I wanted it to show a download button, I switched to Phtoswipe 4, and when I clicked the download button, the browser didn't download the image directly, but reopened a tab to display the image. I searched and found out that it is because the download attribute of the A tag is only applicable to the case of the same origin of the domain name. I opened your Demo Site in Chrome and it also opened a new tab to display the image.

Yes, that is the expected behaviour. A browser will only offer something to download if the server sends a HTTP-Header in the response with Content-Disposition: attachment or Content-Disposition: attachment; filename=....

Also see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition.

The attribute download in a link also indicates, that the linked resource should be offered for downloading, but there it is not defined how the browser actually handles that. Browsers also may just open the image even if the link contains download. Also see: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a

The only solution to this would be to implement a proxy service which fetches the image on its own and sends the result with the required HTTP headers to force the browser to download it instead of opening it directly.

I will see what I can do - but this will only be done when I also add a download option for PhotoSwipe 5, so don't expect anything soon.

@GHNature
Copy link
Author

GHNature commented Oct 28, 2022

Since I wanted it to show a download button, I switched to Phtoswipe 4, and when I clicked the download button, the browser didn't download the image directly, but reopened a tab to display the image. I searched and found out that it is because the download attribute of the A tag is only applicable to the case of the same origin of the domain name. I opened your Demo Site in Chrome and it also opened a new tab to display the image.

Yes, that is the expected behaviour. A browser will only offer something to download if the server sends a HTTP-Header in the response with Content-Disposition: attachment or Content-Disposition: attachment; filename=....

Also see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition.

The attribute download in a link also indicates, that the linked resource should be offered for downloading, but there it is not defined how the browser actually handles that. Browsers also may just open the image even if the link contains download. Also see: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a

The only solution to this would be to implement a proxy service which fetches the image on its own and sends the result with the required HTTP headers to force the browser to download it instead of opening it directly.

I will see what I can do - but this will only be done when I also add a download option for PhotoSwipe 5, so don't expect anything soon.

Could you please consider adding a thumbnail button in Photoswipe 5? Just like this I searched for a long time to find this function in this plugin.

@arnowelzel
Copy link
Owner

Could you please consider adding a thumbnail button in Photoswipe 5? Just like this I searched for a long time to find this function in this plugin.

This is not just simple button.

The thumbnail view itself also has to be programmed first which includes a number challenges, like moving the lightbox to the left when the thumbnail view opens and implementing the thumbnail view as well which includes the question what images to use for the thumbnails. Keep in mind that PhotoSwipe will only display links to images on he website - it does not know anything at all about thumbnails. You can even create a lightbox without a thumbnail at all, like here:

https://wordpress-demo.arnowelzel.de/lightbox-with-photoswipe-external-images/

See the text "Click here to open the image." which is a link to an image without thumbnail.

Due to the effort needed to do this and the problems connected with that - sorry, no this will not happen.

But as always: pull requests are welcome - if someone else wants to add this as a function I am happy to add the contribution to the plugin.

@arnowelzel arnowelzel added enhancement New feature or request help wanted Extra attention is needed labels Mar 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants