@mediagoom/chunk-upload
v0.0.19
Published
A Browser to node.js chunked uploader
Downloads
8
Readme
chunk-upload
Browser to node.js chunked uploader
This module has three components:
- A server side express middleware to receive chunks
- A client module which can be used in both nodejs or the browser
- A ui component to be used in the browser
In order to see a working sample:
npm install
npm run build
npm run server
Open your browser in http://localhost:3000/index.html
In order to use chunk-upload in your project run:
npm i -S @mediagoom/chunk-upload
Server
After installing in your express server add:
const uploader = require('@mediagoom/chunk-upload');
const app = express();
app.use('/upload', uploader({base_path: <destination> + '/'}));
//this is called at the end of the upload
app.put('/upload/:id?', (req, res) => {
//the file path
console.write(req.uploader);
res.send('OK');
});
Client
To use the client module use:
import {UploadManager} from '@mediagoom/chunk-upload/lib';
To use the client ui module use:
import {build} from '@mediagoom/chunk-upload/lib/ui';
To use the client css:
npm i -D sass
If you use webpack in your webpack.config.js
const sass = require('node-sass');
const readFileSync = require('fs').readFileSync;
function svg_inline(value)
{
const val = value.getValue();
const path = path.resolve('./assets', val);
const content = readFileSync(path);
return new sass.types.String('url("data:image/svg+xml;base64,' + content.toString('base64') + '")');
}
..........
test: /\.scss$/
,use: [
,'css-loader'
, { loader: 'sass-loader'
, options: {
functions: {
'svg-load($value1)' : svg_inline
}
}
}