Reference server implementation in Go of tus: the open protocol for resumable file uploads
Go to file
Marius 2e44bad1b0 Add tests for Config structure 2016-03-11 20:46:34 +01:00
.hooks Rename postfinish hook to post-finish 2016-02-22 14:04:14 +01:00
cmd/tusd Merge branch 'master' into composer 2016-02-22 14:12:24 +01:00
consullocker Document functions for handling StoreComposers 2016-03-11 20:17:43 +01:00
filestore Document functions for handling StoreComposers 2016-03-11 20:17:43 +01:00
limitedstore Add initial draft of StoreComposr 2016-02-21 23:25:35 +01:00
memorylocker Document functions for handling StoreComposers 2016-03-11 20:17:43 +01:00
s3store Document functions for handling StoreComposers 2016-03-11 20:17:43 +01:00
uid rewrite tusd 2015-02-01 14:57:57 +01:00
vendor/github.com Update dependencies 2016-02-11 16:15:25 +01:00
.gitignore Move infra builder to own repo 2015-08-19 16:34:49 +02:00
.gitmodules Update dependencies 2016-02-11 16:15:25 +01:00
.travis.yml Exclude .hooks direcory from tests 2016-02-22 14:08:24 +01:00
LICENSE.txt rewrite tusd 2015-02-01 14:57:57 +01:00
README.md Remove Go 1.2 as supported target 2016-02-11 16:21:58 +01:00
appveyor.yml Do not run test verbose on AppVeyor 2016-01-17 15:55:00 +01:00
composer.go Document functions for handling StoreComposers 2016-03-11 20:17:43 +01:00
composer.mgo Document functions for handling StoreComposers 2016-03-11 20:17:43 +01:00
composer_test.go Add example for NewStoreComposer() 2016-03-04 22:14:46 +01:00
concat_test.go Use assertions library for tests 2016-01-20 16:40:19 +01:00
config.go Add tests for Config structure 2016-03-11 20:46:34 +01:00
config_test.go Add tests for Config structure 2016-03-11 20:46:34 +01:00
cors_test.go Add tests for Config structure 2016-03-11 20:46:34 +01:00
datastore.go Add initial draft of StoreComposr 2016-02-21 23:25:35 +01:00
doc.go Add documentation about using tusd 2016-03-04 22:13:13 +01:00
get_test.go Extract tests into tusd_test package 2015-12-25 22:33:27 +01:00
handler.go Add documentation about using tusd 2016-03-04 22:13:13 +01:00
handler_test.go Remove unused GetReader function from tests 2016-01-23 22:45:31 +01:00
head_test.go Extract tests into tusd_test package 2015-12-25 22:33:27 +01:00
options_test.go Add tests for Config structure 2016-03-11 20:46:34 +01:00
patch_test.go Use assertions library for tests 2016-01-20 16:40:19 +01:00
post_test.go Add RespectForwardedHeaders option to handlers 2016-01-16 15:27:35 +01:00
terminate_test.go Extract concatenation into own interface 2016-01-20 15:33:17 +01:00
unrouted_handler.go Merge branch 'master' into composer 2016-02-22 14:12:24 +01:00

README.md

tusd

Build Status Build status

tusd is the official reference 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.

Protocol version: 1.0.0

Getting started

Requirements:

  • Go (1.3 or newer)

Running tusd from source:

Clone the git repository and cd into it.

git clone git@github.com:tus/tusd.git
cd tusd

Now you can run tusd:

go run cmd/tusd/main.go

Using tusd manually

Besides from running tusd using the provided binary, you can embed it into your own Golang program:

package main

import (
	"github.com/tus/tusd"
	"github.com/tus/tusd/filestore"
	"net/http"
)

func main() {
	// Create a new FileStore instance which is responsible for
	// storing the uploaded file on disk in the specified directory.
	// If you want to save them on a different medium, for example
	// a remote FTP server, you can implement your own storage backend
	// by implementing the tusd.DataStore interface.
	store := filestore.FileStore{
		Path: "./uploads",
	}

	// Create a new HTTP handler for the tusd server by providing
	// a configuration object. The DataStore property must be set
	// in order to allow the handler to function.
	handler, err := tusd.NewHandler(tusd.Config{
		BasePath:              "files/",
		DataStore:             store,
	})
	if err != nil {
		panic("Unable to create handler: %s", err)
	}

	// Right now, nothing has happened since we need to start the
	// HTTP server on our own. In the end, tusd will listen on
	// and accept request at http://localhost:8080/files
	http.Handle("files/", http.StripPrefix("files/", handler))
	err = http.ListenAndServe(":8080", nil)
	if err != nil {
		panic("Unable to listen: %s", err)
	}
}

If you need to customize the GET and DELETE endpoints use tusd.NewUnroutedHandler instead of tusd.NewHandler.

Implementing own storages

The tusd server is built to be as flexible as possible and to allow the use of different upload storage mechanisms. By default the tusd binary includes filestore which will save every upload to a specific directory on disk.

If you have different requirements, you can build your own storage backend which will save the files to S3, a remote FTP server or similar. Doing so is as simple as implementing the tusd.DataStore interface and using the new struct in the configuration object. Please consult the documentation about detailed information about the required methods.

Running the testsuite

go test -v ./...

License

This project is licensed under the MIT license, see LICENSE.txt.