Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plupload Html5 preview after Fileselect

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.

like image 610
Email Avatar asked Jun 27 '13 09:06

Email


2 Answers

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).

like image 111
sabel Avatar answered Sep 22 '22 07:09

sabel


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)

like image 31
Make Web Avatar answered Sep 26 '22 07:09

Make Web