Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

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

— asked March 29th 2010 by Franck T
  • download
  • force
  • header
  • wekbit
0 Comments

5 Answers

  • Why not just fetch it via Titanium.Network APIs and save it using Titanium.Filesystem to disk?

    — answered May 28th 2010 by Jeff Haynie
    permalink
    0 Comments
  • 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

    — answered April 4th 2011 by Allan Brazute
    permalink
    0 Comments
  • Bump

    — answered June 14th 2011 by Allan Brazute
    permalink
    0 Comments
  • Same situation here. Any help?

    Thx a lot

    — answered August 14th 2012 by Javier Prieto
    permalink
    0 Comments
  • 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
        }
    });
    
    — answered August 14th 2012 by Allan Brazute
    permalink
    1 Comment
    • URL: ev.target.href

      — commented August 14th 2012 by Allan Brazute
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.