filedrop

package module
v1.0.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2018 License: MIT Imports: 12 Imported by: 1

README

filedrop

Travis CI CodeCov Latest Release Issues License

Too lightweight file storage server with HTTP API.

HTTP API

POST single file to /filedrop to save it. For example:

POST /filedrop/screenshot.png
Content-Type: image/png
Content-Length: XXXX

You will get response with full file URL, like this one:

http://example.com/filedrop/41a8f78c-ce06-11e8-b2ed-b083fe9824ac/screenshot.png

Actually only UUID is used for file access. So you can change last part of URL how you like:

http://example.com/filedrop/41a8f78c-ce06-11e8-b2ed-b083fe9824ac/amazing-screenshot.png

You can specify max-uses and store-time-secs to override default settings from server configuration (however you can't set value higher then configured).

POST /filedrop/screenshot.png?max-uses=5&store-time-secs=3600

Following request will store file screenshot.png for one hour (3600 seconds) and allow it to be downloaded not more than 10 times.

Authorization

filedrop supports very basic access control. Basically, it can execute SQL query with contents of Authorization header and file name. If query returns 1

  • access will be allowed, if query returns 0 or fails - client will get 403.

See configuration example for details.

Installation

go get or clone this repo and build binary from filedropd package. Pass path to configuration in first argument. You are perfect.

Configuration

Documented example is included in repo, check it out.

Embedding

If your backend server is written in Golang or you are not a big fan of microservices architecture - you can run filedrop server as part of your program. See documentation for details.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrFileDoesntExists = errors.New("file doesn't exists")

Functions

This section is empty.

Types

type AuthConfig

type AuthConfig struct {

	// Used only in embedded interface.
	Callback func(*http.Request) bool `yaml:"omitempty"`
}

type Config

type Config struct {
	Limits        LimitsConfig
	DB            DBConfig
	DownloadAuth  AuthConfig
	UploadAuth    AuthConfig
	StorageDir    string
	HTTPSUpstream bool
}
var Default Config

type DBConfig

type DBConfig struct {
	Driver string
	DSN    string
}

type LimitsConfig

type LimitsConfig struct {
	MaxUses      uint
	MaxStoreSecs uint
	MaxFileSize  uint
}

type Server

type Server struct {
	DB     *db
	Conf   Config
	Logger *log.Logger
	// contains filtered or unexported fields
}

filedrop server structure, implements http.Handler.

func New

func New(conf Config) (*Server, error)

func (*Server) AddFile

func (s *Server) AddFile(contents io.Reader, contentType string, maxUses uint, storeUntil time.Time) (string, error)

AddFile adds file to storage and returns assigned UUID which can be directly substituted into URL.

func (*Server) Close

func (s *Server) Close() error

func (*Server) GetFile

func (s *Server) GetFile(fileUUID string) (r io.Reader, contentType string, err error)

GetFile opens file for reading.

Note that access using this function is equivalent to access through HTTP API, so it will count against usage count, for example. To avoid this use OpenFile(fileUUID).

func (*Server) OpenFile

func (s *Server) OpenFile(fileUUID string) (io.Reader, error)

func (*Server) RemoveFile

func (s *Server) RemoveFile(fileUUID string) error

RemoveFile removes file from database and underlying storage.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

Jump to

Keyboard shortcuts

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