upload-element

1.0.1 • Public • Published

upload-element

read files from html <input type="file"> elements

example

First write some html with an <input type="file"> element:

<html>
  <body>
    <input id="upload" type="file" multiple>
    <script src="bundle.js"></script> 
  </body>
</html>
var upload = require('upload-element');
 
var elem = document.querySelector('#upload')
upload(elem, { type: 'text' }, function (err, files) {
    files.forEach(function (file) {
        document.bodyinnerHTML += file.target.result;
    });
});

methods

var upload = require('upload-element')

upload(elem, opts, cb)

Read elem, an <input type="file"> or <input type="file" multiple> element.

When the user uploads a file and all the files have been read, cb(err, results) fires with an error or the list of files.

results is an array of objects, each with:

  • result.target - target object, has result property with the string or arraybuffer of the file contents
  • result.file - file object, has name and other properties

Set opts.type to control the type of result.target.result:

  • 'text' - string of content
  • 'url' - string base64 data url
  • 'array' - arraybuffer of content (default)

install

With npm do:

npm install upload-element

license

MIT

Dependents (0)

Package Sidebar

Install

npm i upload-element

Weekly Downloads

18

Version

1.0.1

License

MIT

Last publish

Collaborators

  • nopersonsmodules