upload

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package upload validates and stores user-uploaded files in object storage.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type File

type File struct {
	Name        string
	ContentType string
	Size        int64
	Open        func() (io.ReadCloser, error)
}

File is an uploaded file, decoupled from multipart so services and tests don't depend on HTTP types.

func FromHeader

func FromHeader(fh *multipart.FileHeader) *File

FromHeader adapts a multipart upload; it returns nil for a nil header.

type Files

type Files struct {
	// contains filtered or unexported fields
}

Files saves and removes uploads.

func New

func New(store Storage) *Files

func (*Files) Exists

func (f *Files) Exists(ctx context.Context, key string) (bool, error)

Exists reports whether key is present in the store.

func (*Files) Remove

func (f *Files) Remove(ctx context.Context, key string)

Remove deletes an object. Failures are logged, not returned: as on the classic site, a failed S3 delete never blocks the database change.

func (*Files) Save

func (f *Files) Save(ctx context.Context, file *File, category string) (string, error)

Save checks the content type against the allow-list, uploads the file as <category>/<uuid><ext>, and returns the object key.

func (*Files) URL

func (f *Files) URL(key string) string

URL returns the public URL for key, or "" when key is empty.

type Storage

type Storage interface {
	Put(ctx context.Context, key string, body io.Reader, size int64, contentType string) error
	Delete(ctx context.Context, key string) error
	Exists(ctx context.Context, key string) (bool, error)
	PublicURL(key string) string
}

Storage is the object store (satisfied by *storage.Store).

Directories

Path Synopsis
Package uploadtest provides an in-memory upload.Storage for tests.
Package uploadtest provides an in-memory upload.Storage for tests.

Jump to

Keyboard shortcuts

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