Documentation
¶
Index ¶
- Constants
- Variables
- func BindWithApiRequest(r *http.Request, req HttpApiMethod) error
- func GetUploadFile(c *http.Request, key string) (fileName string, file []byte, err error)
- func GetUploadFileWithLimit(c *http.Request, key string, maxBytes int64) (fileName string, file []byte, err error)
- type HttpApiMethod
- type HttpApiRequest
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 ¶
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
}
Click to show internal directories.
Click to hide internal directories.