Documentation
¶
Overview ¶
Package upload provides the multipart file upload handler for tmux-webui.
Overview ¶
Handler wraps a destination directory and a maximum file size. The HTTP() method returns an http.HandlerFunc that:
- Enforces the size cap via http.MaxBytesReader (returns 413 if exceeded).
- Parses the "file" field from a multipart/form-data body.
- Sanitizes the filename: strips directory components, replaces any character that is not \w, -, or . with an underscore (mirrors the Python re.sub(r"[^\w\-.]", "_", name) one-liner).
- Prefixes the sanitized name with a Unix millisecond timestamp to avoid collisions (e.g. "1715000000000_report.pdf").
- Streams the upload to disk with io.Copy and returns {"path": "<full destination path>"} on success.
Wire-up (server.go) ¶
uploadH := upload.New(cfg.UploadDir, 50<<20)
mux.HandleFunc("POST /api/upload", uploadH.HTTP())
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler is the upload handler bound to a destination directory.
func New ¶
New creates a Handler that writes files to dir. Pass maxBytes = 0 to use the 50 MB default.
func (*Handler) HTTP ¶
func (h *Handler) HTTP() http.HandlerFunc
HTTP returns an http.HandlerFunc for POST /api/upload. The request must be multipart/form-data with a "file" field.
Click to show internal directories.
Click to hide internal directories.