问题
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