Giter Club home page Giter Club logo

tus-node-server's Introduction

tus-node-server

Tus logo

tus is a protocol based on HTTP for resumable file uploads. Resumable means that an upload can be interrupted at any moment and can be resumed without re-uploading the previous data again. An interruption may happen willingly, if the user wants to pause, or by accident in case of an network issue or server outage.

tus-node-server is an official implementation of the tus resumable upload protocol. The protocol specifies a flexible method to upload files to remote servers using HTTP. The special feature is the ability to pause and resume uploads at any moment allowing to continue seamlessly after e.g. network interruptions.

It is capable of accepting uploads with arbitrary sizes and storing them locally on disk, on Google Cloud Storage or on AWS S3 (or any other S3-compatible storage system). Due to its modularization and extensibility, support for nearly any other cloud provider could easily be added to tus-node-server

๐Ÿ“ฃ Read the 1.0.0 announcement post: new packages, rewrite in TypeScript, and much more.

Contents

When should I use this?

When you want reliable, resumable uploads. Together with a client like tus-js-client or Uppy, you'll have a plug-and-play experience.

tus-node-server in particular makes sense if you want to host a Node.js server or integrate it into your existing one. There are also other mature servers, like tusd, tusdotnet, rustus, and many others.

Quick start

A standalone server which stores files on disk.

const {Server} = require('@tus/server')
const {FileStore} = require('@tus/file-store')

const host = '127.0.0.1'
const port = 1080
const server = new Server({
  path: '/files',
  datastore: new FileStore({directory: './files'}),
})

server.listen({host, port})

A tus server integrated into your existing Node.js server. @tus/server has no dependencies so it can be integrated in any server-side framework. More examples can be found in @tus/server.

const fastify = require('fastify')({ logger: true });
const {Server} = require('@tus/server');
const {FileStore} = require('@tus/file-store');

const tusServer = new Server({
  path: '/files',
  datastore: new FileStore({ directory: './files' })
})

fastify.addContentTypeParser(
    'application/offset+octet-stream', (request, payload, done) => done(null);
);
fastify.all('/files', (req, res) => {
    tusServer.handle(req.raw, res.raw);
});
fastify.all('/files/*', (req, res) => {
    tusServer.handle(req.raw, res.raw);
});
fastify.listen(3000, (err) => {
    if (err) {
        fastify.log.error(err);
        process.exit(1);
    }
});

Packages

Extensions

The tus protocol supports optional extensions. Below is a table of the supported extensions.

Extension file-store s3-store gcs-store
Creation โœ… โœ… โœ…
Creation With Upload โœ… โœ… โœ…
Expiration โœ… โŒ โŒ
Checksum โŒ โŒ โŒ
Termination โœ… โœ… โŒ
Concatenation โŒ โŒ โŒ

Demos

Start the demo server using Local File Storage

yarn build && yarn demo

Start up the demo server using AWS S3. The environment variables AWS_BUCKET, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and AWS_REGION need to be present.

yarn build && yarn demo:s3

Start up the demo server using Google Cloud Storage. A keyfile.json needs to be present in the root of the repository.

yarn build && yarn demo:gcs

Then navigate to the demo (localhost:1080) which uses tus-js-client.

Types

All packages are fully typed with TypeScript.

Compatibility

All packages require Node.js 16.0+.

Contribute

See contributing.md.

License

MIT ยฉ tus

tus-node-server's People

Contributors

bhstahl avatar murderlon avatar dependabot[bot] avatar mitjap avatar acconut avatar js3692 avatar gormed avatar spencern avatar kvz avatar gerdus avatar radev avatar naumf avatar lukeburpee avatar greenkeeperio-bot avatar fenos avatar erikjwaxx avatar mhf-ir avatar pguyson avatar phillip-causing avatar rictorres avatar spencerbart avatar stevewillard avatar samal-rasmussen avatar tameribrahim avatar toddgeist avatar yuriyyakym avatar ujvzolee avatar andywirv avatar liknens avatar sh 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.