1. #1
    Sencha User
    Join Date
    Jan 2012
    Posts
    8
    Vote Rating
    0
    samos is on a distinguished road

      0  

    Default Download File From Content

    Download File From Content


    Hello,

    I need to download a generated file from content.

    I get content from ajax and after i want to download a file WITH this content.

    Is is possible ?

    I already tried to create a form with a hidden field, datas are not sent, same for textarea, because the datas are too big ?

    Thanks for help,

    Samos

  2. #2
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    8,910
    Vote Rating
    443
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    I need to download a generated file from content.
    Is the file generated on the server and you want to display/save it to client?

    I already tried to create a form with a hidden field, datas are not sent, same for textarea, because the datas are too big
    I am not sure I understand this ... do you mean sending file to server?

    Please detail what you are trying to achieve.

    Scott.

  3. #3
    Sencha User
    Join Date
    Jan 2012
    Posts
    8
    Vote Rating
    0
    samos is on a distinguished road

      0  

    Default


    Hello Scott,

    I receive from server the content of a file (via ajax request), i want to create a file and save it on local hard drive with this content.

    Samuel

  4. #4
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    8,910
    Vote Rating
    443
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    This is a security risk and not supported. Imagine some website trying to save a file to your PC.
    There are however several approaches online I believe if you search around the net.

    If you send the file, you can use window.open(file) to open a save dialog.

    Scott.

  5. #5
    Sencha User
    Join Date
    Jan 2012
    Posts
    8
    Vote Rating
    0
    samos is on a distinguished road

      0  

    Default


    Yes i want to save the file with a "save as" dialog, but i really don't know how to do.

  6. #6
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    8,910
    Vote Rating
    443
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    This is more of a browser issue ... server has to set the content, browser will open.

    Here is an example:
    http://examples.extjs.eu/

    Go to Form/Downloading Files

    Has demo and source.

    Scott.

  7. #7
    Sencha User
    Join Date
    Jan 2012
    Posts
    8
    Vote Rating
    0
    samos is on a distinguished road

      0  

    Default


    It is not a good example because the form request a file (download.php), me i get only content of this file, and from this content generate a file.

  8. #8
    Sencha User
    Join Date
    Jan 2012
    Posts
    8
    Vote Rating
    0
    samos is on a distinguished road

      0  

    Default SOLVED

    SOLVED


    var results = Ext.decode(response.responseText) ;
    window.open("data:text/csv;base64," + window.btoa(results), "_blank");

  9. #9
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    8,910
    Vote Rating
    443
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    As I mentioned above .. glad you got it working ...

    Scott.

  10. #10
    Sencha Premium Member
    Join Date
    Aug 2012
    Posts
    7
    Vote Rating
    0
    somewhereinlondon is on a distinguished road

      0  

    Default Hmm..

    Hmm..


    I'm also trying to download a file (generated on the fly, on the server).

    When I try:
    Code:
    var results = Ext.decode(response.responseText) ;
    window.open("data:text/csv;base64," + window.btoa(results), "_blank");
    as in:
    Code:
    Ext.Ajax.request({
        url: app_constants.EXPORT_TO_EXCEL_URL,
    method: 'POST',       componentName: gridtoexport,
    
            success: 
    function(result, request) {
    var results = Ext.decode(result.responseText) ;
                window.open(
    "data:text/csv;base64," + window.btoa(results), "_blank");
    },
    
            failure: 
    function(result, request) {
    
                Ext.MessageBox.alert(
    'Failed', result.responseText);
            },
            jsonData: payload
            });
        };

    .. I get (in the browser):
    Uncaught Ext.Error: You're trying to decode an invalid JSON String

    How can I get ext to understand that this is a binary file and not a json string ? (I've already set the correct content type etc. on the serverside).

    Any ideas how I can read the binary file out of response.responseText ?
    Oh - and I'm using Ext js 4.1.2

Thread Participants: 2

Tags for this Thread

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..."