Saw a similar question at Download a file using Javascript but this one is specific to IE and I'm using extjs and alfresco (opsoro). I can get a download prompt for text files fine in Opera, Chrome, and Firefox, but not IE.
Below is a list of what I've tried so far, which all work on other browsers except IE7.
document.location = downloadLocation;
window.open(downloadLocation,'Download');
location.href = downloadLocation;
When downloading other mimetypes (csv, xls), they download fine using any of the methods mentioned above.
You may need some help from the backend. Instead of serving the file statically, the backend app can load and serve the file contents with a content disposition header. That is guaranteed to invoke a download.
Content-disposition: attachment; filename=hello.txt
I don't know how you could do it with Alfresco, though.
Edit: Wait! Check this out: http://forums.alfresco.com/en/viewtopic.php?f=36&t=21356&p=70252
Related
I need to allow users to click a link to a .bat file on an IIS 6.0 server directory and view that file as plain text. I have set the MIME type for .bat file to "text/plain." This works perfectly in both Chrome and Firefox. The way this works is that I have a button that launches a separate popup browser window to the .bat file. Example is below:
onclick=\"window.open(\'\/eemcontrolpanel\/jobs\/" + encodedFileName +"\',\'popUpWindow\',\'height=500,width=400,left=100,top=100,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no, status=yes\');\">View Script</button>").scrollHeight;
As I said, this works in both Chrome and Firefox, but for some reason, IE 8 immediately closes the popup and asks me if I want to Run or Save the file.
I think IE goes by filename extension to detect its an executable file. Maybe you could give it another name by adding a header like:
'Content-Disposition: attachment; filename="thebat.txt"'
I have a PHP web application in which users can click a button to download an XML file generated on the fly. It has worked well for a long time, but suddenly I am getting bug reports from a single Internet Explorer user (I only have a screenshot showing the bug). I need your help to figure out possible causes.
First, the button click in the web GUI is handled with jQuery which has a JavaScript window.location statement:
$("#generate-button").click(function() {
...
window.location = "generateXml.phtml";
}
generateXml.phtml is PHP which creates an XML string which is returned:
header('Content-Type: application/xml');
header('Content-Disposition: attachment; filename=xmlFile.xml');
echo $xmlString;
Up until now, users have always been prompted whether to open or save the xmlFile.xml (which is correct). Now however, a user of Internet Explorer (version unknown but it appears to be IE10) is prompted whether to open or save generateXml_phtml:
Note that IE has replaced the . (dot) with _ (underscore). It seems the PHP server code in generateXml.phtml is not even executed.
Do you have any ideas? I cannot replicate the bug using IE on my own system.
Can you give a direct link to the problem? Try change the extenssion to .php its weird if the file ins´t being processed the web server should only give you a executed code not the raw code, maybe is something wrong with .phtml extenssion...
I am writing Dropbox web-application and use Client Library for the Dropbox:
https://github.com/dropbox/dropbox-js.
For uploading file choosen by user I use method writeFile. Html object File(< input type=file >) is passed as parameter data. It works fine in FireFox.
It is said that this library is tested against IE9 and IE10.
Does method writeFile work in IE8?
If it does not work in IE8 then is there way to use html form for uploading file to dropbox?
Dropbox docs does not give example how to upload file by html form.
Is there some example?
writeFile takes the contents of the file, not an HTML input tag. See http://coffeedoc.info/github/dropbox/dropbox-js/master/classes/Dropbox/Client.html#writeFile-instance.
This means your JavaScript has to have access to the actual contents of the file to use writeFile. The HTML5 File API might help here, but it certainly doesn't work in IE8.
I think this means you'll need to upload the file to your own servers (via a standard form submit) and then transfer the file from there to Dropbox.
EDIT: Remove a clause claiming general poor support for File API. It looks like it's not that bad: http://caniuse.com/#search=file%20api
I have an offline html file that generates and saves a CSV by setting window.location to
data:text/csv;base64,Intfa2V5fSIsInt...
However, in Safari this just brings up the CSV in the browser.
Setting the url to:
data:application/csv;base64,Intfa2V5fSIsInt...
forces Safari to download the file - but it gets a generic file name of just 'Unknown-3'. Is there a way to specify the file name?
First, a warning:application/csv isn't a valid MIME type, so the fact that it "works" for you in this case is purely an implementation quirk that could very well change in the future. (For example, Safari displays application/octet-stream, which I'd expect to download.)
HTML5 does have a new <a download="file.name"> attribute. This forces the browser to download the file to disk; it uses the attribute's value as the default file name. It does work in conjunction with a data URI or a blob URI. (Demo)
However, it is currently only supported by Chrome (14+). Safari 5.1 ignores the attribute.
A possible alternative is to use the Filesystem API, but that gives you a sandboxed folder to work with. You can't—for example—save a file directly to the user's Documents folder. Instead, you can write a file to the sandbox and then redirect to file on the new filesystem schema:
location.assign('filesystem:http://example.com/temporary/somefile.csv');
This should invoke the UA's download mechanism (with the right filename!), but I haven't tested this, so it is possible Safari will just display the file anyway.
According to the RFC 2397 no. There is no way.
Also read this related question.
Lets assume I have a file on a CDN (Cloud Files from Rackspace) and a static html page with a link to that file. Is there any way I can force download this file (to prevent it from opening in the browser -- for mp3s for example)?
We could make our server read the file and set the corresponding header to:
header("Content-Type: application/force-download")
but we have about 5 million downloads per month so we would rather let the CDN take care of that.
Any ideas?
There’s no way to do this in HTML or JavaScript. There is now! (Ish. See #BruceAldrige’s answer below.)
The HTTP Content-Disposition header is what tells browsers to download the files, and that’s sent by the server. You have to configure the CDN to send that header with whichever files you want to browser to download instead of display.
Unhelpfully, I’m entirely unfamiliar with Rackspace’s Cloud Files service, so I don’t know if they allow this, nor how to do it. Just found a page from December 2009 that suggests not thought, sadly:
Cloud Files cannot serve a file with the 'Content-Disposition: attachment' HTTP header. Therefore, a download link that would work perfectly in any other service may result in the browser rendering the file directly. This was confirmed by Rackspace engineers. :-(
http://drupal.org/node/656714
I know that you can with Amazon’s CloudFront service, as it’s backed by S3 (see e.g. http://blog.cloudberrylab.com/2009/06/how-to-set-custom-http-headers-for.html)
You can use the download attribute:
<a href="http..." download></a>
https://stackoverflow.com/a/11024735/21460
However, it’s not currently supported by Safari (7) or IE (11).
Yes, you can do this through the cloudfiles API. Using the method stream allows you to stream the contents of files in - setting your own headers etc.
A crazy idea: download via XMLHttpRequest and serve a data: URL with the content type you want? :P