upload

package
v1.4.8 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package upload provides type-safe file upload handling with OpenAPI support

Index

Constants

View Source
const (
	DefaultMaxFileSize  = 32 << 20 // 32MB
	DefaultMaxTotalSize = 64 << 20 // 64MB
	DefaultMaxFiles     = 10
)

Default file upload limits

Variables

This section is empty.

Functions

func Bind

func Bind(c echo.Context, req interface{}, config *Config) error

Bind binds multipart form data to a request struct containing File fields

func HasFileFields

func HasFileFields(t reflect.Type) bool

HasFileFields checks if a type contains File fields

func IsFileSliceType

func IsFileSliceType(t reflect.Type) bool

IsFileSliceType checks if a type is []*File

func IsFileType

func IsFileType(t reflect.Type) bool

IsFileType checks if a type is *File or File

func IsMultipartRequest

func IsMultipartRequest(c echo.Context) bool

IsMultipartRequest checks if the request is multipart/form-data

Types

type Config

type Config struct {
	// MaxFileSize is the maximum size for a single file (default: 32MB)
	MaxFileSize int64
	// MaxTotalSize is the maximum total size for all files (default: 64MB)
	MaxTotalSize int64
	// AllowedMIMETypes lists allowed MIME types (empty = all allowed)
	AllowedMIMETypes []string
	// AllowedExtensions lists allowed file extensions (e.g., ".jpg", ".pdf")
	AllowedExtensions []string
	// MaxFiles is the maximum number of files for multi-upload (default: 10)
	MaxFiles int
	// PreserveFile keeps the multipart.File open for later reading
	// If false (default), file content is read into memory immediately
	PreserveFile bool
}

Config configures file upload handling

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the default file upload configuration

type Error

type Error struct {
	Field   string `json:"field"`
	Message string `json:"message"`
}

Error represents a file upload validation error

func (*Error) Error

func (e *Error) Error() string

type Errors

type Errors []Error

Errors is a collection of file upload errors

func (Errors) Error

func (e Errors) Error() string

type FieldInfo

type FieldInfo struct {
	Name       string
	FormTag    string
	IsMultiple bool
	Required   bool
}

FieldInfo contains information about a file upload field

func GetFileFields

func GetFileFields(t reflect.Type) []FieldInfo

GetFileFields returns information about File fields in a type

type File

type File struct {
	// Filename is the original name of the uploaded file
	Filename string `json:"filename"`
	// Size is the file size in bytes
	Size int64 `json:"size"`
	// ContentType is the MIME type of the file
	ContentType string `json:"content_type"`
	// Header contains the MIME header of the file part
	Header textproto.MIMEHeader `json:"-"`
	// contains filtered or unexported fields
}

File represents an uploaded file with metadata

func (*File) Close

func (f *File) Close() error

Close closes the underlying file

func (*File) Extension

func (f *File) Extension() string

Extension returns the file extension (with dot)

func (*File) Open

func (f *File) Open() (io.ReadCloser, error)

Open returns an io.ReadCloser for reading the file content

func (*File) Read

func (f *File) Read() ([]byte, error)

Read reads the entire file content into memory

func (*File) SaveTo

func (f *File) SaveTo(destPath string) error

SaveTo saves the file to the specified path

type Files

type Files []*File

Files is a convenience type for multiple file uploads

type FormFieldInfo

type FormFieldInfo struct {
	Name       string
	FormTag    string
	Type       reflect.Type
	Required   bool
	Validation string
}

FormFieldInfo contains information about a form field

func GetNonFileFields

func GetNonFileFields(t reflect.Type) []FormFieldInfo

GetNonFileFields returns information about non-file form fields

Jump to

Keyboard shortcuts

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