chatformdocs
Blocks

File upload

A file or image: a CV, a screenshot, a receipt.

Advancedfile_upload

A file or image: a CV, a screenshot, a receipt.

How it gets answered — arrives out of band (an upload, a payment, or a booking).

Configuration

Fields specific to file_upload. The fields every block has — id, ref, title, required, visibility, media, agentHints, prefillParam, identityField — are documented once.

file_upload configuration
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "buttonLabel": {
      "type": "string",
      "maxLength": 60
    },
    "type": {
      "type": "string",
      "const": "file_upload"
    },
    "accept": {
      "minItems": 1,
      "maxItems": 20,
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "maxFiles": {
      "default": 1,
      "type": "integer",
      "minimum": 1,
      "maximum": 10
    },
    "maxSizeMB": {
      "default": 10,
      "type": "number",
      "minimum": 0.1,
      "maximum": 100
    }
  },
  "required": [
    "id",
    "ref",
    "title",
    "type",
    "accept"
  ],
  "$defs": {
    "__schema0": {
      "type": "object",
      "properties": {
        "op": {
          "type": "string",
          "enum": [
            "and",
            "or"
          ]
        },
        "conditions": {
          "default": [],
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "left": {
                "oneOf": [
                  {
                    "type": "object",
                    "properties": {
                      "kind": {
                        "type": "string",
                        "const": "ref"
                      },
                      "ref": {
                        "type": "string",
                        "pattern": "^[a-z][a-z0-9_]{1,40}$"
                      }
                    },
                    "required": [
                      "kind",
                      "ref"
                    ]
                  },
                  {
                    "type": "object",
                    "properties": {
                      "kind": {
                        "type": "string",
                        "const": "variable"
                      },
                      "name": {
                        "type": "string",
                        "pattern": "^[a-z][a-z0-9_]{0,40}$"
                      }
                    },
                    "required": [
                      "kind",
                      "name"
                    ]
                  },
                  {
                    "type": "object",
                    "properties": {
                      "kind": {
                        "type": "string",
                        "const": "hidden"
                      },
                      "name": {
                        "type": "string",
                        "pattern": "^[a-zA-Z_][a-zA-Z0-9_.-]{0,60}$"
                      }
                    },
                    "required": [
                      "kind",
                      "name"
                    ]
                  },
                  {
                    "type": "object",
                    "properties": {
                      "kind": {
                        "type": "string",
                        "const": "literal"
                      }
                    },
                    "required": [
                      "kind"
                    ]
                  }
                ]
              },
              "op": {
                "type": "string",
                "enum": [
                  "eq",
                  "neq",
                  "gt",
                  "gte",
                  "lt",
                  "lte",
                  "contains",
                  "not_contains",
                  "starts_with",
                  "ends_with",
                  "matches_regex",
                  "is_empty",
                  "is_not_empty",
                  "is_checked",
                  "is_not_checked",
                  "includes",
                  "not_includes",
                  "ranked_above",
                  "ranked_below"
                ]
              },
              "value": {
                "anyOf": [
                  {
                    "type": "string"
                  },
                  {
                    "type": "number"
                  },
                  {
                    "type": "boolean"
                  },
                  {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  }
                ]
              }
            },
            "required": [
              "left",
              "op"
            ]
          }
        },
        "groups": {
          "default": [],
          "type": "array",
          "items": {
            "$ref": "#/$defs/__schema0"
          }
        }
      },
      "required": [
        "op"
      ]
    }
  }
}

In a generated draft these arrive as config pairs: accept=<any, or some of images|pdf|documents|spreadsheets|presentations|audio|video, or formats like png|docx>, maxFiles=<1-10>, maxSizeMB=<0.1-100>. Leave accept out unless the request limits which files are allowed, then name only the kinds it allows..

What you receive

GET /v1/forms/{id} and every "next question" projects blocks through toPublicBlock. For the example above:

PublicBlock
{
  "id": "blk_file0001",
  "ref": "q_resume",
  "type": "file_upload",
  "title": "Upload your CV",
  "required": true,
  "imageKey": null,
  "media": null,
  "accept": [
    "application/pdf"
  ],
  "maxFiles": 1,
  "maxSizeMB": 1
}

What you send

File descriptors, as returned by the upload confirm step.

type Answer = { fileId: string; filename: string; mime: string; size: number; r2Key: string }[];
curl -X POST https://api.chatform.in/v1/responses/{RESPONSE_ID}/answers \
  -H "x-api-key: $CHATFORM_SECRET_KEY" \
  -H "content-type: application/json" \
  -d '{"ref": "q_resume", "value": [{"fileId":"fil_1","filename":"cv.pdf","mime":"application/pdf","size":1000,"r2Key":"uploads/cv.pdf"}]}'

Errors

CodeWhenMessage
requiredan empty answer on a required blockThis question needs an answer.
type"cv.pdf"Please upload a file.
too_many_files—
file_too_large[{"fileId":"fil_1","filename":"big.pdf","mime":"application/pdf","size":5000000,"r2Key":"uploads/big.pdf"}]"big.pdf" exceeds the 1MB limit.

On this page