Documentation
¶
Overview ¶
templ: version: v0.3.977
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FileUpload ¶
FileUpload renders a file upload component with a DaisyUI file input wrapped in a form. Uploaded files appear in a list below the input, rendered server-side via SSE.
func RemoveHandler ¶
func RemoveHandler(store *Store) http.HandlerFunc
RemoveHandler returns an http.HandlerFunc that removes a file from the store and responds with an SSE patch of the updated file list.
Mount at a dedicated POST path:
r.Post("/api/upload/remove", fileupload.RemoveHandler(store))
func UploadHandler ¶
func UploadHandler(store *Store, opts ...HandlerOption) http.HandlerFunc
UploadHandler returns an http.HandlerFunc that accepts multipart file uploads and responds with an SSE patch of the updated file list.
Mount at a dedicated POST path:
r.Post("/api/upload/files", fileupload.UploadHandler(store))
Types ¶
type HandlerOption ¶
type HandlerOption func(*handlerConfig)
HandlerOption configures upload validation.
func WithAllowedTypes ¶
func WithAllowedTypes(types ...string) HandlerOption
WithAllowedTypes restricts uploads to files whose Content-Type starts with one of the given prefixes (e.g. "image/", "application/pdf").
func WithMaxFileSize ¶
func WithMaxFileSize(bytes int64) HandlerOption
WithMaxFileSize sets the maximum allowed size per file in bytes.
func WithMaxFiles ¶
func WithMaxFiles(n int) HandlerOption
WithMaxFiles sets the maximum number of files allowed per component.
type Props ¶
type Props struct {
// ID uniquely identifies this component instance. Required.
ID string
// Class adds additional CSS classes to the container.
Class string
// Attributes adds arbitrary HTML attributes.
Attributes templ.Attributes
// Multiple allows selecting multiple files.
Multiple bool
// Accept restricts file types (e.g. "image/*", ".pdf,.doc").
Accept string
// UploadURL is the POST endpoint for file uploads.
UploadURL string
// RemoveURL is the POST endpoint for file removal.
RemoveURL string
}
Props configures a FileUpload component.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is a thread-safe in-memory store for uploaded file metadata, keyed by "sessionID:componentID".