Giter Site home page Giter Site logo

node-uploadx's Introduction

node-uploadx

npm version Travis status Build status

Node.js resumable upload middleware. Server-side part of ngx-uploadx

Install

npm install node-uploadx

Optionally, to support

  • AWS S3 Storage:
 npm install aws-sdk
  • Google Cloud Storage:
 npm install google-auth-library

Full installation:

npm install node-uploadx -f

Usage

Express example:

const express = require('express');
const { uploadx } = require('node-uploadx');

const app = express();
const opts = {
  directory: './files',
  onComplete: file => console.log('Upload complete: ', file)
};

app.use('/upload/files', uploadx(opts));

app.listen(3003);

Node http.Server GCS example:

const { Uploadx, GCStorage } = require('node-uploadx');
const http = require('http');
const url = require('url');

const storage = new GCStorage({ bucket: 'uploads' });
const uploads = new Uploadx({ storage });
uploads.on('completed', console.log);

const server = http
  .createServer((req, res) => {
    const pathname = url.parse(req.url).pathname;
    if (pathname === '/upload/files') {
      uploads.handle(req, res);
    } else {
      res.writeHead(404, { 'Content-Type': 'text/plan' });
      res.end('Not Found');
    }
  })
  .listen(3003);

Please navigate to the examples for more.

Options

Available options are:

option type default value description
directory string "files" DiskStorage upload directory
bucket string "node-uploadx" S3 or GCS bucket
path string "/files" Node http base path
allowMIME string[] ["*\*"] Array of allowed MIME types
maxUploadSize string|number "50GB" Limit allowed file size
useRelativeLocation boolean false Generate relative upload link
filename Function Filename generator function
onComplete Function File upload complete callback

For Google Cloud Storage authenticate see GoogleAuthOptions. Also supported GCS_BUCKET, GCS_KEYFILE and GOOGLE_APPLICATION_CREDENTIALS environment variables.

For AWS S3 - Setting Credentials in Node.js and S3_BUCKET, S3_KEYFILE environment variable.

References

Contributing

If you'd like to contribute, please fork the repository and make changes as you'd like. Pull requests are welcome!

License

MIT

node-uploadx's People

Contributors

kukhariev avatar renovate[bot] avatar renovate-bot avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.