Reference server implementation in Go of tus: the open protocol for resumable file uploads
Go to file
Adam Kaplan 766dabc238 Refactoring file locking out of tusd.Handler
* Updated filestore.FileStore implementation to use simple locking scheme. Refactored to make interface use pointers. Removed locks from tusd.Handler
* Refactored sample code to use pointer implementation of FileStore.
* Moved ErrFileLocked variable to datastore.go
2015-10-01 13:40:56 -04:00
cmd/tusd Refactoring file locking out of tusd.Handler 2015-10-01 13:40:56 -04:00
filestore Refactoring file locking out of tusd.Handler 2015-10-01 13:40:56 -04:00
limitedstore add limitedstore 2015-04-11 13:40:39 +02:00
uid rewrite tusd 2015-02-01 14:57:57 +01:00
.gitignore Move infra builder to own repo 2015-08-19 16:34:49 +02:00
.travis.yml Restrict toolchain builds tp required platforms 2015-08-19 18:24:20 +02:00
LICENSE.txt rewrite tusd 2015-02-01 14:57:57 +01:00
README.md Use Travis badge for master branch 2015-07-31 12:36:58 +02:00
appveyor.yml setup golang directories on appveyor 2015-02-28 15:38:03 +01:00
concat_test.go add test for returning offset after concatenation 2015-03-31 23:51:28 +02:00
cors_test.go refactor tests using httpTest 2015-02-17 15:44:12 +01:00
datastore.go Refactoring file locking out of tusd.Handler 2015-10-01 13:40:56 -04:00
get_test.go Close io.Reader if possible 2015-07-28 14:58:52 +02:00
handler.go Refactoring file locking out of tusd.Handler 2015-10-01 13:40:56 -04:00
handler_test.go return new offset after successful PATCH request 2015-03-23 19:02:12 +01:00
head_test.go prevent caching of HEAD responses 2015-05-26 16:17:35 +02:00
options_test.go fix Tus-Extension test 2015-03-23 19:02:39 +01:00
patch_test.go return new offset after successful PATCH request 2015-03-23 19:02:12 +01:00
post_test.go update header names 2015-03-23 18:15:05 +01:00
terminate_test.go update header names 2015-03-23 18:15:05 +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.2 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)
	}
}

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.DateStore 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.