desktop: force download a file using webkit
I've made a file manager using extjs and php server side (remote server).
When a user click on a file (like a pdf) i'd like to open the standard dialog box of webkit to be able to save the file somewhere client side.
For moment, i've tried to create an iframe dynamicaly and then redirect it to the URL of the php remote file which send the pdf.
Here are the headers i'm sending using php :
header('Content-Type: application/octet-stream');
header("Pragma: public");
header("Expires: 0");
header("Content-Length: " . filesize($src));
header('Content-Disposition: attachment; filename="'.basename($src).'"');
This doesn't work. No dialog box to be able to save the file localy.
On safari this code is working.
But using the inspector, i can see that the body content of the iframe contain the binary content of the pdf.
What's the best way to handle that ?
Use titanium socket functions and perhaps some titanium functions to be able to make the user choose where to save the file ?
Fix some of the headers ?
Change something in webkit mimes policy ?
Any help is really welcome on this problem, thanks in advance
5 Answers
-
Why not just fetch it via Titanium.Network APIs and save it using Titanium.Filesystem to disk?
-
I'm trying to do a "specific site" browser. This site have href links to files the user may download.
I too noticed that Titanium downloads the file content to the body of the window.
But when a user click on a link to a file, I wold like to offer actions for that file, like save it, email it or print it. Or at least the save dialog.How can I handle that downloads?
Thx
-
Bump
-
Same situation here. Any help?
Thx a lot
-
My 2c…
Example of how to do using "Ext Core" addEventListener, but you can do that using other methods too:
this.view.contentDocument.body.addEventListener('click', function(ev){ if (ev.target.tagName == 'A') { ev.preventDefault(); ev.stopPropagation(); ... // Now use the Ti.Network.createHTTPClient() to download the "ev.target" URL content } });