uploads

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 18, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyFile       = errors.New("uploaded file is empty")
	ErrFileTooLarge    = errors.New("uploaded file is too large")
	ErrInvalidFileType = errors.New("file extension is not allowed")
)

Functions

func ServeFileForDownload

func ServeFileForDownload(w http.ResponseWriter, r *http.Request, filePath string, opts DownloadOptions) error

ServeFileForDownload serves a file for download with the specified options

Types

type DownloadOptions

type DownloadOptions struct {
	ForceDownload     bool
	SuggestedFilename string
	ContentType       string
	ExtraHeaders      map[string]string
}

func DefaultDownloadOptions

func DefaultDownloadOptions() DownloadOptions

type FileUploadOptions

type FileUploadOptions struct {
	DestinationDir string
	MaxSize        int64
	// AllowedExts is a list of allowed file extensions (without the dot). Leave empty to allow all.
	AllowedExts       []string
	AllowedMimeTypes  []string
	FilenamePrefix    string
	RandomizeFilename bool
}

func DefaultOptions

func DefaultOptions() FileUploadOptions

type SavedFile

type SavedFile struct {
	OriginalName string
	SavedName    string
	SavedPath    string
	Size         int64
	MIMEType     string
}

func SaveMultipleFormFiles

func SaveMultipleFormFiles(r *http.Request, fieldName string, opts *FileUploadOptions) ([]*SavedFile, error)

func SaveSingleFormFile

func SaveSingleFormFile(r *http.Request, fieldName string, opts *FileUploadOptions) (*SavedFile, error)

func SaveUploadedFile

func SaveUploadedFile(file *multipart.FileHeader, opts *FileUploadOptions) (*SavedFile, error)

Jump to

Keyboard shortcuts

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