繁体   English   中英

档案下载-ExtJs 4.2.3

[英]File download - ExtJs 4.2.3

我正在使用ExtJs 4.2.3。 在我的Web应用程序中,我需要下载文件。 为了做到这一点,我使用的是在postFileDownloader中定义的“ FileDownloader”组件

代码是:

Ext.define('myApp.FileDownload', {
   extend: 'Ext.Component',
   alias: 'widget.FileDownloader',
   autoEl: {
      tag: 'iframe',
      cls: 'x-hidden',
      src: Ext.SSL_SECURE_URL
},

load: function(config) {

    var e = this.getEl();
    e.dom.src = config.url +
        (config.params ? '?' + Ext.Object.toQueryString(config.params) : '');

        console.log('in FileDownloader - src: ' + e.dom.src);

        e.dom.onLoad = function() {
        if(e.dom.contentDocument.body.childNodes[0].wholeText == '404') {
            Ext.Msg.show({ 
                title: 'Attachment missing',
                msg: 'File cannot be found on the server !',
                buttons: Ext.Msg.OK,
                icon: Ext.MessageBox.ERROR
            });
        };
    };

}

});

我用代码来称呼它:

downloader.load({
   url: src
});

src是文件的完整路径。

如果我下载Word,Excel,PDF文件,效果很好,则在浏览器的下载栏中可以看到文件引用,但是对于其他数据类型(例如.txt,.jpg),它什么也不做。

我认为这与Extjs或js无关,这是服务器的响应。 看到此下载文本文件,而不是在浏览器中打开

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM