Documentation
¶
Overview ¶
Package upload decodes multipart upload requests with validation errors.
The package is stable core API. It owns transport-level multipart parsing, request and file size checks, required file fields, content-type allowlists, and Problem Details-compatible field errors. It does not own object storage, virus scanning, media processing, persistence, or authorization.
Use DecodeMultipart with Config to parse a request into a Form, then RequireFile to fetch required file fields by name. AllowedContentTypes and MaxFileBytes are small helpers for constructing readable Config values. ValidationProblem and WriteValidationProblem preserve the same error shape as binding and httpx.
Always apply authentication, authorization, total request limits, and application-owned scanning before trusting uploaded content. For examples, see docs/cookbook.md.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllowedContentTypes ¶
AllowedContentTypes returns a normalized content-type allowlist for Config.
func MaxFileBytes ¶
MaxFileBytes returns a file-size limit value for Config.
func ValidationProblem ¶
ValidationProblem maps upload validation errors to Problem Details.
func WriteValidationProblem ¶
func WriteValidationProblem(w http.ResponseWriter, err error)
WriteValidationProblem writes upload validation errors as Problem Details.
Types ¶
type Config ¶
type Config struct {
MaxMemory int64
MaxRequestBytes int64
MaxFileBytes int64
RequiredFiles []string
AllowedContentTypes []string
}
Config configures multipart decoding.
type File ¶
type File struct {
FieldName string
Filename string
ContentType string
Size int64
Header textproto.MIMEHeader
FileHeader *multipart.FileHeader
}
File describes an uploaded multipart file.
func RequireFile ¶
RequireFile returns the first file for a required field.