Node.js resumable upload middleware. Server-side part of ngx-uploadx
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
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.
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.
- https://developers.google.com/drive/api/v3/manage-uploads#resumable
- https://github.com/tus/tus-resumable-upload-protocol/blob/master/protocol.md
If you'd like to contribute, please fork the repository and make changes as you'd like. Pull requests are welcome!