Skip to content

API Reference parrot_formdesigner.api.file_upload

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot_formdesigner.api.file_upload

View source

File-upload handler for the raw upload field types (FEAT-460).

Exposes handle_file_upload — an aiohttp request handler mounted at:

POST /api/v1/{tenant}/forms/{form_uid}/fields/{field_uid}/file-upload

and handle_get_thumbnail — mounted at:

GET /api/v1/{tenant}/forms/{form_uid}/fields/{field_uid}/thumbnail?ref=<encoded-blob-ref>

Handles the binary pipeline for FILE, IMAGE, IMAGE_DROPZONE, and MULTI_UPLOAD field types: multipart parsing, MIME/size enforcement, blob storage persistence, inline data_url encoding, SHA-256 checksums, optional thumbnail generation, and basic chunked-upload support.

Error codes:

  • 400: malformed multipart, no file part, or multiple files on a single-cardinality field (FILE/IMAGE).
  • 404: form not found, field not found, or field is not an upload type.
  • 413: upload exceeds field.constraints.max_file_size_bytes.
  • 415: MIME type not in field.constraints.allowed_mime_types.
  • 500: blob storage failure.

Basic chunked upload: Clients that split a large file into sequential chunks may send each chunk as a raw (non-multipart) request body, tagged with the X-Parrot-Upload-Offset and X-Parrot-Upload-Length headers, plus a client-generated X-Parrot-Upload-Id (stable across all chunks of one upload — required to disambiguate concurrent uploads to the same field). Chunks are buffered in blob storage (one blob per chunk) and reassembled when the final chunk arrives (offset + len(chunk) == total_length). This is NOT full tus-protocol support — see the spec's Non-Goals.

Thumbnail URLs (TASK-2469): FileEnvelope.thumbnail_url is a fetchable path under handle_get_thumbnail (this module), not the raw blob reference — the ref query parameter carries that reference URL-encoded (blob_ref strings are backend-opaque, e.g. temp://... / s3://bucket/..., and contain /, so a query param avoids parsing a backend-specific key shape out of a path segment). No signing/expiry — same unsigned trust model as blob_ref itself.

Alias AbstractBlobStorage

Re-exported from parrot_formdesigner.services.blob_storage.AbstractBlobStorage.

Alias BlobMetadata

Re-exported from parrot_formdesigner.services.blob_storage.BlobMetadata.

Attribute CLIENT_UPLOAD_ID_HEADER

Alias DEFAULT_MAX_INLINE_SIZE

Re-exported from parrot_formdesigner.core.constraints.DEFAULT_MAX_INLINE_SIZE.

Alias FileEnvelope

Re-exported from parrot_formdesigner.core.file_envelope.FileEnvelope.

Alias FormField

Re-exported from parrot_formdesigner.core.schema.FormField.

Alias FormSchema

Re-exported from parrot_formdesigner.core.schema.FormSchema.

Alias ThumbnailService

Re-exported from parrot_formdesigner.services.thumbnail.ThumbnailService.

Alias UPLOAD_FIELD_TYPES

Re-exported from parrot_formdesigner.core.file_envelope.UPLOAD_FIELD_TYPES.

Alias declared_tenant

Re-exported from parrot_formdesigner.api.tenant.declared_tenant.

Alias enforce_membership_unless_public

Re-exported from parrot_formdesigner.api.tenant.enforce_membership_unless_public.

Alias extract_form_uid

Re-exported from parrot_formdesigner.api.handlers.extract_form_uid.

Alias extract_uid

Re-exported from parrot_formdesigner.api.handlers.extract_uid.

Alias file_type_allowed

Re-exported from parrot_formdesigner.core.mime_match.file_type_allowed.

Alias find_field_by_uid

Re-exported from parrot_formdesigner.core.resolution.find_field_by_uid.

Function handle_file_upload

Handle POST /api/v1/{tenant}/forms/{form_uid}/fields/{field_uid}/file-upload.

Streams multipart upload(s) through the file upload pipeline: multipart -> MIME/size check -> blob storage -> FileEnvelope(s) -> JSON.

Supports multiple 'file' parts in one request. Returns a single FileEnvelope for single-cardinality fields (FILE, IMAGE) or a list for multi-cardinality fields (IMAGE_DROPZONE multi, MULTI_UPLOAD).

Accepts X-Parrot-Prior-Blob-Ref header for replacement uploads, and X-Parrot-Upload-Offset / X-Parrot-Upload-Length headers for basic chunked uploads.

Accepts X-Parrot-Client-Upload-Id (idempotency): the same id for the same field names the same blob, so a retried upload (an offline device replaying its queue) returns the same blob_ref and stores no duplicate. Without it every upload gets a fresh random name, exactly as before.

handle_file_upload(request: web.Request) -> web.Response

Parameter Type Default Description
request web.Request The incoming aiohttp web.Request.

Returns: web.Response — JSON response with a single FileEnvelope, a list of FileEnvelopes, or a chunk-accepted acknowledgement (202) for non-final chunks.

Raises:

  • web.HTTPBadRequest — Malformed multipart, no file part, or multiple files on a single-cardinality field.
  • web.HTTPNotFound — Form/field not found, or field is not an upload type.
  • web.HTTPRequestEntityTooLarge — Upload exceeds the size constraint.
  • web.HTTPUnsupportedMediaType — MIME type not allowed.

Function handle_get_thumbnail

Handle GET .../forms/{form_uid}/fields/{field_uid}/thumbnail?ref=.

Streams back a previously generated thumbnail's bytes. ref is the opaque blob_ref embedded (URL-encoded) in a FileEnvelope's thumbnail_url by _finalize_envelope.

handle_get_thumbnail(request: web.Request) -> web.Response

Parameter Type Default Description
request web.Request The incoming aiohttp web.Request.

Returns: web.Response — The thumbnail bytes, Content-Type: image/webp.

Raises:

  • web.HTTPNotFound — Form/field not found, field is not an upload type, the ref query parameter is missing, or the referenced blob cannot be read.

Alias is_single_cardinality

Re-exported from parrot_formdesigner.core.file_envelope.is_single_cardinality.

Attribute logger

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally