tus-node-server
tus is a new open protocol for resumable uploads built on HTTP. This is the tus protocol 1.0.0 node.js server implementation.
⚠️ Attention: We currently lack the resources to properly maintain tus-node-server. This has the unfortunate consequence that this project is in rather bad condition (out-dated dependencies, no tests for the S3 storage, no resumable uploads for the GCS storage etc). If you want to help us with tus-node-server, we are more than happy to assist you and welcome new contributors. In the meantime, we can recommend tusd as a reliable and production-tested tus server. Of course, you can use tus-node-server if it serves your purpose.
Installation
$ npm install tus-node-server
Flexible Data Stores
-
Local File Storage
serverdatastore =path: '/files'; -
Google Cloud Storage
serverdatastore =path: '/files'projectId: 'project-id'keyFilename: 'path/to/your/keyfile.json'bucket: 'bucket-name'; -
Amazon S3
serverdatastore =path: '/files'bucket: 'bucket-name'accessKeyId: 'access-key-id'secretAccessKey: 'secret-access-key'region: 'eu-west-1'partSize: 8 * 1024 * 1024 // each uploaded part will have ~8MB,tmpDirPrefix: 'tus-s3-store';
Quick Start
tus-node-deploy Docker image
Use the$ docker run -p 1080:8080 -d bhstahl/tus-node-deploy
Build a standalone server yourself
const tus = ; const server = ;serverdatastore = path: '/files'; const host = '127.0.0.1';const port = 1080;server;
Express Middleware
Use tus-node-server asconst tus = ;const server = ;serverdatastore = path: '/files'; const express = ;const app = ;const uploadApp = ;uploadAppall'*' serverhandle;app; const host = '127.0.0.1';const port = 1080;app;
Koa or plain Node server
Use tus-node-server withconst http = ;const url = ;const Koa = const tus = ;const tusServer = ; const app = ;const appCallback = app;const port = 1080; tusServerdatastore = path: '/files'; const server = http; server
Features
Events:
Execute code when lifecycle events happen by adding event handlers to your server.
const Server = Server;const EVENTS = EVENTS; const server = ;server;
-
EVENT_FILE_CREATED
: Fired when aPOST
request successfully creates a new fileExample payload:
{ file: { id: '7b26bf4d22cf7198d3b3706bf0379794', upload_length: '41767441', upload_metadata: 'filename NDFfbWIubXA0' } }
-
EVENT_ENDPOINT_CREATED
: Fired when aPOST
request successfully creates a new upload endpointExample payload:
{ url: 'http://localhost:1080/files/7b26bf4d22cf7198d3b3706bf0379794' }
-
EVENT_UPLOAD_COMPLETE
: Fired when aPATCH
request finishes writing the fileExample payload:
{ file: { id: '7b26bf4d22cf7198d3b3706bf0379794', upload_length: '41767441', upload_metadata: 'filename NDFfbWIubXA0' } }
GET
handlers:
Custom Add custom GET
handlers to suit your needs, similar to Express routing.
const server = ;server
Custom file names:
const fileNameFromUrl = { return requrl;} serverdatastore = path: '/files' namingFunction: fileNameFromUrl;
Development
Start the demo server using Local File Storage
$ npm run demo
Or start up the demo server using Google Cloud Storage
$ npm run gcs_demo
Then navigate to the demo (localhost:1080) which uses tus-js-client