Plupload Html5 preview after Fileselect

孤人 提交于 2019-12-04 09:35:05

问题


http://jsfiddle.net/VjeTk/78/

Using Plupload.com File uploader

i want a preview image after file selection for html5 runtime browsers.

Therefor i add to the FilesAdded Event

uploader.bind('FilesAdded', function(up, files) {
    for (var i in files) {
        $('filelist').innerHTML += '<div id="' + files[i].id + '">' + files[i].name + ' (' + plupload.formatSize(files[i].size) + '<img src="' + SOMEHOWLOCALSOURCEOFIMAGE +'"/>') <b></b></div>';
    }
});

Problem is Plupload does not deliver the usual binary file object like html does. Thanks for ANY help.


回答1:


Plupload 2 has an image object, which you can use: https://github.com/moxiecode/moxie/wiki/Image

File.getSource() and mOxie.Image.embed() are the methods, you are interested in.

https://github.com/moxiecode/plupload/wiki/File#wiki-getSource--method

https://github.com/moxiecode/moxie/wiki/Image#wiki-embed-eloptions-method

The jQuery UI queue widget uses this.

Here's a working example for a custom uploader: http://jsfiddle.net/Ec3te/2/

Works even in browsers that don't support HTML5 File API (yes, even IE6).




回答2:


function showImagePreview( file ) {
	var reader = new window.FileReader();
	reader.readAsDataURL(file.getNative());
	reader.onload = function () {
		base64data = reader.result;
		base64data = base64data.substring(base64data.indexOf(",") + 1);
	  var base_64_url = "data:" + file.type + ";base64," + base64data;
	}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

Alternative showImagePreview (Withour mOxie)



来源:https://stackoverflow.com/questions/17339899/plupload-html5-preview-after-fileselect

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