fileapi

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 12, 2026 License: MIT Imports: 12 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func UserIDFromContext

func UserIDFromContext(ctx context.Context) string

UserIDFromContext extracts the uploader identity from context.

func WithUserID

func WithUserID(ctx context.Context, userID string) context.Context

WithUserID attaches an uploader identity to context for file transport use.

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

func (h *Handler) WithMaxSize(size int64) *Handler

WithMaxSize sets the maximum allowed file size for uploads.

Jump to

Keyboard shortcuts

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