Skip to content

API Reference parrot_formdesigner.api.uploads

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

parrot_formdesigner.api.uploads

View source

REST field upload handler for FormDesigner (FEAT-170).

Exposes handle_rest_upload — an aiohttp request handler mounted at:

POST /api/v1/forms/{form_uid}/fields/{field_uid}/upload

The handler follows this pipeline:

  1. Resolve the FormField via app["form_registry"] and core.resolution.find_field_by_uid (FEAT-393 — field_uid, not field_id, is the path param; renaming a field's field_id never breaks its upload URL).

  2. Verify the field is FieldType.REST; return 404 otherwise.

  3. Parse the multipart body, streaming bytes to AbstractBlobStorage.

  4. Enforce MIME and size constraints from field.constraints.

  5. Build AuthContext from the inbound request.

  6. Honour X-Parrot-Prior-Blob-Ref header — delete the prior blob after the new one is durably written (delete failure appends a warning string, does NOT 500).

  7. Call RestFieldResolver.resolve() with the spec and payload.

  8. Return a JSON envelope:

    { "success": bool, "answer": , "raw_value": , "blob_ref": str | null, "display": str | null, "warnings": [str, ...], "error": str | null }

Error codes:

  • 400: malformed multipart or no file part.
  • 404: form not found or field not found / not of type REST.
  • 413: upload exceeds field.constraints.max_file_size_bytes.
  • 415: MIME type not in field.constraints.allowed_mime_types.
  • 500: unexpected exception (resolver contract guarantees never-raise for known errors; RestFieldResult.success=False maps to 200).

Lazy-init contract: app["blob_storage"] and app["rest_resolver"] may be None. On first request, this module constructs default instances from env vars.

Alias AdditionalArg

Re-exported from parrot_formdesigner.services.rest_field_resolver.AdditionalArg.

Alias FieldType

Re-exported from parrot_formdesigner.core.types.FieldType.

Alias FormField

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

Alias RestCallbackInput

Re-exported from parrot_formdesigner.services.rest_field_resolver.RestCallbackInput.

Alias RestFieldResolver

Re-exported from parrot_formdesigner.services.rest_field_resolver.RestFieldResolver.

Alias RestFieldSpec

Re-exported from parrot_formdesigner.services.rest_field_resolver.RestFieldSpec.

Alias declared_tenant

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

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_rest_upload

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

Streams a multipart upload through the REST field pipeline: multipart → MIME/size check → blob storage → resolver → JSON envelope.

The X-Parrot-Prior-Blob-Ref request header, if present, identifies a previously-uploaded blob that should be deleted after the new blob is durably written (idempotent; delete failure appends a warning).

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

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

Returns: web.Response — JSON response with the resolver result envelope.

Raises:

  • web.HTTPBadRequest — If field_uid is not a well-formed UUID, or if multipart is malformed or has no file part.
  • web.HTTPNotFound — If form or field not found, or field is not REST.
  • web.HTTPRequestEntityTooLarge — If upload exceeds size constraint.
  • web.HTTPUnsupportedMediaType — If MIME is not in allowed list.

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