Files: 7bfc8ffe94be45777d9884bcd5c9db880dcc2d97 / modules_core / file-input.js
973 bytesRaw
1 | var u = require('../util') |
2 | var h = require('hyperscript') |
3 | var pull = require('pull-stream') |
4 | var mime = require('simple-mime')('application/octect-stream') |
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 | if (!file) return |
17 | var reader = new FileReader() |
18 | reader.onload = function () { |
19 | pull( |
20 | pull.values(split(new Buffer(reader.result), 64*1024)), |
21 | add(function (err, blob) { |
22 | if(err) return console.error(err) |
23 | onAdded({ |
24 | link: blob, |
25 | name: file.name, |
26 | size: reader.result.length || reader.result.byteLength, |
27 | type: mime(file.name) |
28 | }) |
29 | |
30 | }) |
31 | ) |
32 | } |
33 | reader.readAsArrayBuffer(file) |
34 | } |
35 | }) |
36 | } |
37 | |
38 |
Built with git-ssb-web