Skip to content

Instantly share code, notes, and snippets.

@oniram88
Last active December 4, 2017 13:09
Show Gist options
  • Save oniram88/10730767 to your computer and use it in GitHub Desktop.
Save oniram88/10730767 to your computer and use it in GitHub Desktop.
File Download
Ext.define( 'DownloadFile', {
requires:['Ext.form.Panel'],
downloadFile:function ( config ) {
config = config || {};
var url = config.url,
method = config.method || 'POST',// Either GET or POST. Default is POST.
params = config.params || {};
// Create form panel. It contains a basic form that we need for the file download.
var form = Ext.create( 'Ext.form.Panel', {
standardSubmit:true,
url:url,
method:method
} );
// Call the submit to begin the file download.
form.submit( {
target:'_blank', // Avoids leaving the page.
params:params
} );
// Clean-up the form after 100 milliseconds.
// Once the submit is called, the browser does not care anymore with the form object.
Ext.defer( function () {
form.close();
}, 100 );
}
} );
@oniram88
Copy link
Author

Tu use this:
include in your class with mixin:

mixins:['DownloadFile'],

and then in your class you can use:

 this.downloadFile( {
        method:'GET',
        url:'url/to/file.pdf',
        params:{
            foo:bar
        }
    } );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment