http_util

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultMaxUploadBytes = 32 << 20

DefaultMaxUploadBytes is the default maximum size in bytes for a single uploaded file (32MB). Use GetUploadFileWithLimit to override per call.

Variables

View Source
var ErrInvalidFileName = errors.New("upload file name contains invalid characters")
View Source
var ErrUploadTooLarge = errors.New("upload file exceeds maximum allowed size")

Functions

func BindWithApiRequest

func BindWithApiRequest(r *http.Request, req HttpApiMethod) error

func GetUploadFile

func GetUploadFile(c *http.Request, key string) (fileName string, file []byte, err error)

GetUploadFile reads the first multipart form file for key and returns its sanitized filename and body, with a default max size of DefaultMaxUploadBytes.

func GetUploadFileWithLimit added in v0.1.23

func GetUploadFileWithLimit(c *http.Request, key string, maxBytes int64) (fileName string, file []byte, err error)

GetUploadFileWithLimit reads the first multipart form file for key and returns its sanitized filename and body. Files larger than maxBytes return ErrUploadTooLarge. The returned fileName is the base name only; path traversal and null bytes are rejected.

Types

type HttpApiMethod

type HttpApiMethod interface {
	NewRequest() HttpApiRequest
	Decode2(c *http.Request, contentType string, r HttpApiRequest) (err error)
}

type HttpApiRequest

type HttpApiRequest interface {
	Method() string
}

Jump to

Keyboard shortcuts

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