4.4.2 • Published 3 years ago

@hieutran106/node-uploadx v4.4.2

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

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

optiontypedefault valuedescription
directorystring"files"DiskStorage upload directory
bucketstring"node-uploadx"S3 or GCS bucket
pathstring"/files"Node http base path
allowMIMEstring[]["*\*"]Allowed MIME types
maxUploadSizestring\|number"5TB"File size limit
metaStorageMetaStorageProvide custom meta storage
metaStorageConfigMetaStorageOptionsConfigure metafiles storage
maxMetadataSizestring\|number"4MB"Metadata size limit
validationValidationUpload validation options
useRelativeLocationbooleanfalseUse relative urls
filenameFunctionName generator function
onCompleteOnCompleteOn upload complete callback
clientDirectUploadbooleanUpload by a compatible client directly to the GCS
expirationExpirationOptionsConfiguring 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