Documentation
¶
Overview ¶
Package fileapi provides an HTTP handler for tenant-aware file operations. It composes x/data/file storage and metadata implementations with the contract error model.
Tenant identity must be attached via x/tenant/core.WithTenantID before reaching any handler method — typically by middleware in the calling application. User identity is optional and may be attached via WithUserID.
Index ¶
- func UserIDFromContext(ctx context.Context) string
- func WithUserID(ctx context.Context, userID string) context.Context
- type Handler
- func (h *Handler) Delete(w http.ResponseWriter, r *http.Request)
- func (h *Handler) Download(w http.ResponseWriter, r *http.Request)
- func (h *Handler) GetInfo(w http.ResponseWriter, r *http.Request)
- func (h *Handler) GetURL(w http.ResponseWriter, r *http.Request)
- func (h *Handler) List(w http.ResponseWriter, r *http.Request)
- func (h *Handler) Upload(w http.ResponseWriter, r *http.Request)
- func (h *Handler) WithMaxSize(size int64) *Handler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func UserIDFromContext ¶
UserIDFromContext extracts the uploader identity from context.
Types ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler provides HTTP endpoints for file operations.
func NewHandler ¶
func NewHandler(storage datafile.Storage, metadata datafile.MetadataManager) *Handler
NewHandler creates a new file handler with a default maximum upload size of 100 MiB.
func (*Handler) Delete ¶
func (h *Handler) Delete(w http.ResponseWriter, r *http.Request)
Delete soft-deletes a file. DELETE /files/{id}
func (*Handler) Download ¶
func (h *Handler) Download(w http.ResponseWriter, r *http.Request)
Download streams file content. GET /files/{id}
func (*Handler) GetInfo ¶
func (h *Handler) GetInfo(w http.ResponseWriter, r *http.Request)
GetInfo returns file metadata. GET /files/{id}/info
func (*Handler) GetURL ¶
func (h *Handler) GetURL(w http.ResponseWriter, r *http.Request)
GetURL returns a temporary access URL for the file. GET /files/{id}/url?expiry=3600
func (*Handler) List ¶
func (h *Handler) List(w http.ResponseWriter, r *http.Request)
List returns a paginated list of files. GET /files?page=1&page_size=20&mime_type=image/jpeg&uploaded_by=user1 Requires tenant identity in request context.
func (*Handler) Upload ¶
func (h *Handler) Upload(w http.ResponseWriter, r *http.Request)
Upload handles file upload via multipart form. POST /files Form fields: file (required), generate_thumb, thumb_width, thumb_height. Requires tenant identity in request context.
func (*Handler) WithMaxSize ¶
WithMaxSize sets the maximum allowed file size for uploads.