Plupload get uploader object (v2.1.2) for file reader

孤人 提交于 2019-12-11 10:35:40

问题


I'm trying to read the selected file with HTML5 File Reader.

FilesAdded: function(up, files){

    try{
        var file = jQuery('#'+uploader.id+'_html5').get(0).files[0];
        var reader = new FileReader();

        reader.onload = function () {
            preview.find('.text').fadeOut('fast', function(){
                $(this).siblings('img').prop({src: reader.result}).fadeIn('fast');
            });
        }

        reader.readAsDataURL(file);
        uploader.refresh();
    } catch(e) {
        console.log(e.message);
    }
},

In the older versions of the plupload i could get the uploader id with jQuery('#'+uploader.id+'_html5').get(0).files[0]

But i have updated my pluploader version to 2.1.2 and it is not working now.

Cannot read property 'files' of undefined

Any idea?

By the way, uploader is defined as plupload.Uploader.


Solution with Files

var file = files[0].getNative();

回答1:


For who still searching an answer to this;

Solution is more simple.

Solution with files variable in FilesAdded method;

var file = files[0].getNative();

And done. You have the file object itself.

HTML5 File reader accepts and reads that easily.



来源:https://stackoverflow.com/questions/24366312/plupload-get-uploader-object-v2-1-2-for-file-reader

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!