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.
Link
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.
Download Link
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
Related
I have requirement in which I need to enable save as option if the user downloads the file from the my web application.Is there any way by which i can do it through java script or setting some attribute in th response header.(This should override the browser setting which user has done for by setting the download option in settings)
Note: I cannot handle or create file in my web application (client side)space as files are large which crashes the application so I am using content-disposition and letting the browser to handle the download
Not at the moment due to user experience and security concerns (users have to do it manually).
But the upcoming FileSystem API allows for it but is not fully implemented yet.
Mailto URI does not allow to attach file due to security concern. Is there any other way to achieve this functionality?
When user clicks on sendmail button in my application, it is populating outlook desktop application (as I have used mailto URI), so I can only allow to use mailto option in my coding.
My application constructed by HTML,JS,Node.js (I should not use nodemailer)
This is not possible. There will be security concerns if it was. You can ask the user to upload the file to the server, retrieve the file and add the URL to the uploaded file in the message body in mailto:.
I have a webservice that will respond with a pdf on certain post requests.
I need to be able, in javascript, to download this pdf and embed it on my page. How would I do that?
I don't have a direct URL only the data passed back by the AJAX
You can try out PDF.js. However, it doesn't support all the browser.
An alternative with IE support is thatyou could just insert a iFrame, and change the src to the location of the PDF.
We are using HTML5 and javascript in one of our applications. The requirement is when the user clicks on a button we should download a file containing all the user entered data. There should be no server interaction to do this.
By using ActiveX object we can do this. But it is limited to Internet Explorer only.
By setting the response headers at the server also we can achieve this. But we can't use server interaction to do this.
We tried to use base64 data with mime type as 'application/octect-stream'. It is downloading "xxx.part" file to the local system with the exact data. But we are unable to set our own file name and extension (as we can't use .part as extension) to the file.
Please suggest us a way to download a file from the browser without server interaction with the desired file name and extension that works with all the browsers.
Currently not possible without using ActiveX or Flash. Take a look at Downloadify and see if it works for you.
We tried to use base64 data with mime type as 'application/octect-stream'
Have you tried setting appropriate response header?
Response.AppendHeader("Content-Disposition", "attachment; filename=name.ext");
I want to give a link of network local file in browser, where users can open from there.
link would be like this file.xls
In IE6,7,8 it doesn't work.
Any idea ?
You can use the File URI scheme.
http://en.wikipedia.org/wiki/File_URI_scheme