Files: 3e002b3d827c2d8867edbf6541a3e6eadc4b32b6 / modules / file-input.js
935 bytesRaw
1 | var u = require('../util') |
2 | var h = require('hyperscript') |
3 | var pull = require('pull-stream') |
4 | var mime = require('mime-types') |
5 | var split = require('split-buffer') |
6 | |
7 | var plugs = require('../plugs') |
8 | |
9 | var add = plugs.first(exports.sbot_blobs_add = []) |
10 | |
11 | exports.file_input = function FileInput(onAdded) { |
12 | |
13 | return h('input', { type: 'file', |
14 | onchange: function (ev) { |
15 | var file = ev.target.files[0] |
16 | var reader = new FileReader() |
17 | reader.onload = function () { |
18 | pull( |
19 | pull.values(split(new Buffer(reader.result), 64*1024)), |
20 | add(function (err, blob) { |
21 | if(err) return console.error(err) |
22 | onAdded({ |
23 | link: blob, |
24 | name: file.name, |
25 | size: reader.result.length || reader.result.byteLength, |
26 | type: mime.contentType(file.name) |
27 | }) |
28 | |
29 | }) |
30 | ) |
31 | } |
32 | reader.readAsArrayBuffer(file) |
33 | } |
34 | }) |
35 | } |
36 | |
37 | |
38 | |
39 | |
40 | |
41 |
Built with git-ssb-web