filestore

package
v2.9.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 11, 2026 License: MIT Imports: 11 Imported by: 11

Documentation

Overview

Package filestore provide a storage backend based on the local file system.

FileStore is a storage backend used as a handler.DataStore in handler.NewHandler. It stores the uploads in a directory specified in two different files: The `[id].info` files are used to store the fileinfo in JSON format. The `[id]` files without an extension contain the raw binary data uploaded. No cleanup is performed so you may want to run a cronjob to ensure your disk is not filled up with old and finished uploads.

Related to the filestore is the package filelocker, which provides a file-based locking mechanism. The use of some locking method is recommended and further explained in https://tus.github.io/tusd/advanced-topics/locks/.

Index

Constants

View Source
const (
	// StorageKeyPath is the key of the path of uploaded file in handler.FileInfo.Storage
	StorageKeyPath = "Path"
	// StorageKeyInfoPath is the key of the path of .info file in handler.FileInfo.Storage
	StorageKeyInfoPath = "InfoPath"
)
View Source
const DefaultDirPerm = 0775
View Source
const DefaultFilePerm = 0664

Variables

This section is empty.

Functions

This section is empty.

Types

type FileStore

type FileStore struct {
	// Path is the relative or absolute path to store files in. FileStore does not
	// check whether the path exists; use os.MkdirAll in this case on your own.
	Path string

	// DirModePerm is the file mode (e.g. 0775) used when creating directories
	// for uploads. Only the permission bits are used. If zero, DefaultDirPerm
	// is used by New.
	DirModePerm fs.FileMode

	// FileModePerm is the file mode (e.g. 0664) used when creating upload files
	// and their .info files. Only the permission bits are used. If zero,
	// DefaultFilePerm is used by New.
	FileModePerm fs.FileMode
}

See the handler.DataStore interface for documentation about the different methods.

func New

func New(path string) FileStore

New creates a new file based storage backend. The directory specified will be used as the only storage entry. This method does not check whether the path exists, use os.MkdirAll to ensure. The returned store uses DefaultDirPerm and DefaultFilePerm; set DirModePerm and FileModePerm on the result to override.

func (FileStore) AsConcatableUpload

func (store FileStore) AsConcatableUpload(upload handler.Upload) handler.ConcatableUpload

func (FileStore) AsLengthDeclarableUpload

func (store FileStore) AsLengthDeclarableUpload(upload handler.Upload) handler.LengthDeclarableUpload

func (FileStore) AsServableUpload added in v2.7.0

func (store FileStore) AsServableUpload(upload handler.Upload) handler.ServableUpload

func (FileStore) AsTerminatableUpload

func (store FileStore) AsTerminatableUpload(upload handler.Upload) handler.TerminatableUpload

func (FileStore) GetUpload

func (store FileStore) GetUpload(ctx context.Context, id string) (handler.Upload, error)

func (FileStore) NewUpload

func (store FileStore) NewUpload(ctx context.Context, info handler.FileInfo) (handler.Upload, error)

func (FileStore) UseIn

func (store FileStore) UseIn(composer *handler.StoreComposer)

UseIn sets this store as the core data store in the passed composer and adds all possible extension to it.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL