mediagoom / chunk-upload

Browser to node js chunked uploader
5 stars 1 forks source link
chunk-upload upload upload-file upload-server

Build Status codecov Coverage Status Language grade: JavaScript Known Vulnerabilities Greenkeeper badge

chunk-upload

Browser to node.js chunked uploader

This module has three components:

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
                            }
                        }
                    }