Documentation
¶
Overview ¶
Package upload provides type-safe file upload handling with OpenAPI support
Index ¶
- Constants
- func Bind(c echo.Context, req interface{}, config *Config) error
- func HasFileFields(t reflect.Type) bool
- func IsFileSliceType(t reflect.Type) bool
- func IsFileType(t reflect.Type) bool
- func IsMultipartRequest(c echo.Context) bool
- type Config
- type Error
- type Errors
- type FieldInfo
- type File
- type Files
- type FormFieldInfo
Constants ¶
const ( DefaultMaxFileSize = 32 << 20 // 32MB DefaultMaxTotalSize = 64 << 20 // 64MB DefaultMaxFiles = 10 )
Default file upload limits
Variables ¶
This section is empty.
Functions ¶
func HasFileFields ¶
HasFileFields checks if a type contains File fields
func IsFileSliceType ¶
IsFileSliceType checks if a type is []*File
func IsMultipartRequest ¶
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 FieldInfo ¶
FieldInfo contains information about a file upload field
func GetFileFields ¶
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) Open ¶
func (f *File) Open() (io.ReadCloser, error)
Open returns an io.ReadCloser for reading the file content
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