0

how can I download image without open in browser from another subdomain/domain when I click to download link?

a tag download attribute doesn't work if my page is on another subdomain.

my page is address: https://y.xxx.com/page.html

html code:

<a id="download" href="https://cdn.xxx.com/1.jpg" download>download</a>

I don't want open image on browser. I need to direct download with html or js. is there any way download image from another subdomain or domain (all browser)?

zero298
  • 25,467
  • 10
  • 75
  • 100
Goksel
  • 227
  • 1
  • 3
  • 10
  • When you say "direct download", do you mean you don't want a confirmation box asking the user if they want to download the file? Because you can't get rid of that. That's to prevent malicious scripts from imposing files on the users computer. – zero298 Feb 20 '20 at 15:35
  • the technical part is that you need to have the image sent as `application/octet-stream` instead the normal `image/xxx` content type, so the browser will download, instead showing. Either create a proxy to do that, or find a free service that does the same – balexandre Feb 20 '20 at 15:37
  • did you also try to specify a filename? (i.e. add a value to the download attribute) – Johannes Feb 20 '20 at 15:37
  • You need to add a `Content-Disposition: attachment` header to the response. You can only do that if you can control the HTTP response from the server hosting the image. If you don't control the server, then you need to copy (e.g. by being a proxy) the image to a server you control. – Quentin Feb 20 '20 at 15:38
  • @balexandre — There's no need to give bad `Content-Type` data. The `Content-Disposition` header works fine. – Quentin Feb 20 '20 at 15:38

0 Answers0