@hieutran106/node-uploadx

4.4.2 • Public • Published

node-uploadx

npm version Build status commits since latest release Snyk Vulnerabilities

Node.js resumable upload middleware. Server-side part of ngx-uploadx Supported APIs: Google resumable v3.0, tus 1.0, multipart upload. Capable store uploads locally on disk, on Google Storage or on AWS S3.

🌩 Installation

All-In-One:

npm install node-uploadx

Separate modules can also be used to save disk space and for faster installation process.:

  • core module:

    npm install @uploadx/core
  • Google Cloud Storage support:

    npm install @uploadx/gcs
  • AWS S3 support:

    npm install @uploadx/s3

Usage

Express example:

const express = require('express');
const { uploadx } = require('@uploadx/core');

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

Some available options: :

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[] ["*\*"] Allowed MIME types
maxUploadSize string|number "5TB" File size limit
metaStorage MetaStorage Provide custom meta storage
metaStorageConfig MetaStorageOptions Configure metafiles storage
maxMetadataSize string|number "4MB" Metadata size limit
validation Validation Upload validation options
useRelativeLocation boolean false Use relative urls
filename Function Name generator function
onComplete OnComplete On upload complete callback
clientDirectUpload boolean Upload by a compatible client directly to the GCS
expiration ExpirationOptions Configuring the cleanup of abandoned and completed uploads

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

Package Sidebar

Install

npm i @hieutran106/node-uploadx

Weekly Downloads

11

Version

4.4.2

License

MIT

Unpacked Size

272 kB

Total Files

122

Last publish

Collaborators

  • hieutran106