From 42add99e64c8cc75ed47e2e88b2bd31e4374fed7 Mon Sep 17 00:00:00 2001 From: Tady Date: Sun, 17 Sep 2017 19:27:17 +0300 Subject: [PATCH 1/2] added blob reader FileReaderJS.setupBlob(blob,opt) .... --- filereader.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/filereader.js b/filereader.js index ddeb815..24bf8c6 100644 --- a/filereader.js +++ b/filereader.js @@ -16,6 +16,7 @@ See http://github.com/bgrins/filereader.js for documentation. var FileReaderJS = window.FileReaderJS = { enabled: false, setupInput: setupInput, + setupBlob: setupBlob, setupDrop: setupDrop, setupClipboard: setupClipboard, setSync: function (value) { @@ -151,7 +152,30 @@ See http://github.com/bgrins/filereader.js for documentation. processFileList(e, e.dataTransfer.files, instanceOptions); } } + // setupFile: bind the 'change' event to an input[type=file] + function setupBlob(blob, opts) { + + if (!FileReaderJS.enabled) { + return; + } + + if(blob.constructor !== Array && blob.constructor !== Function){ + if(blob.name === undefined){ + blob.name = "blob"; + } + blob = [blob]; + }else{ + + if(blob[0].name === undefined){ + blob[0].name = "blob"; + } + } + + var instanceOptions = extend(extend({}, FileReaderJS.opts), opts); + + processFileList(null, blob, instanceOptions); + } // setupDrop: bind the 'drop' event for a DOM element function setupDrop(dropbox, opts) { @@ -255,7 +279,6 @@ See http://github.com/bgrins/filereader.js for documentation. // processFileList: read the files with FileReader, send off custom events. function processFileList(e, files, opts) { - var filesLeft = files.length; var group = { groupID: getGroupID(), From b8029c627a5c364ed748c485c6f45abdabbb83fd Mon Sep 17 00:00:00 2001 From: Tady Date: Sun, 17 Sep 2017 19:28:48 +0300 Subject: [PATCH 2/2] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index a5e387d..c717c6e 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ This plugin is open source under the MIT License. It was developed in conjuncti FileReaderJS.setupInput(document.getElementById('file-input'), opts); FileReaderJS.setupDrop(document.getElementById('dropzone'), opts); FileReaderJS.setupClipboard(document.body, opts); + FileReaderJS.setupBlob(blob, opts); ## If you have jQuery: $("#file-input, #dropzone").fileReaderJS(opts);