Taztingo
Taztingo

Reputation: 1945

Download file through Android Chrome Browser

I'm trying to make it so that a file from my web server can be downloaded to an Android mobile device. I want the user to be able to press a Download button on the site, and then they will have the option to save it on there phone's sd card.

The only way I can think of doing this is by using FTP, and having the button navigate the user to ftp://username:pass@webserver/file.blah

Is there another way, using strictly HTML5 and JS?

I have tried using the download tag, but that doesn't seem to work. Instead of downloading the image it redirects them to the page with the image on it.

<a href="/img/cir.png" download="cir.png">Link</a>

Upvotes: 0

Views: 4364

Answers (1)

adarsh
adarsh

Reputation: 6978

HTML5 solution

To force downloading a file, if you are using HTML5, then you can use the download attribute by defining the anchor tag like this.

<a href="/path-to-image/image.png" download="download.png">Download Link</a>

Server-side solution

It is likely that the user's browser doesn't support the download attribute. Check this. So the other solution invloves the server-side. You can use the Content-Disposition HTTP header. Serve this as one of the headers of the HTTP response for the download route. This will force the browser to download the file as an attachment.

Content-Disposition: attachment; filename="download.png"

RFC Read section 19.5.1

Upvotes: 4

Related Questions