> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://reference.flatfile.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://reference.flatfile.com/_mcp/server.

# Upload a file

POST https://api.x.flatfile.com/v1/files
Content-Type: multipart/form-data

Reference: https://reference.flatfile.com/api-reference/files/upload

## Authentication

- `Authorization` header (bearer token, required) — Bearer authentication of the form `Bearer <token>`, where token is your auth token.

## Request

### Body (multipart/form-data)

This endpoint expects a multipart form containing a file.

- `spaceId` (string, required)
- `environmentId` (string, required)
- `mode` (enum, optional) — The storage mode of file to insert, defaults to "import"
- `file` (file, required) — A binary payload containing the file contents
- `actions` (list of Action, optional) — The actions attached to the file
- `origin` (enum, optional) — The origin of the file, ie filesystem

## Response

### 200

- `data` (File, required) — Any uploaded file of any type

## Errors

### 400 Bad Request Error

- `errors` (list of Error, required)

## Types

### File

Any uploaded file of any type

- `id` (string, required) — File ID
- `name` (string, required) — Original filename
- `ext` (string, required) — Extension of the file
- `mimetype` (string, required) — MIME Type of the file
- `encoding` (string, required) — Text encoding of the file
- `status` (enum, required) — Status of the file. Partial: File is uploaded but not yet processed. Analyzing: Smart Extract is running. Analyzed: Smart Extract has finished running. Complete: File has been extracted and is ready to be used. Archived: File has been archived. Purged: File has been purged. Failed: File has failed to be extracted.
  - Allowed values: `partial`, `analyzing`, `analyzed`, `complete`, `archived`, `purged`, `failed`
- `size` (integer, required) — Size of file in bytes
- `bytesReceived` (integer, required) — Number of bytes that have been uploaded so far (useful for progress tracking)
- `createdAt` (datetime, required) — Date the file was created
- `updatedAt` (datetime, required) — Date the file was last updated
- `spaceId` (string, required) — Space ID
- `description` (string, optional) — Description of the file
- `mode` (enum, optional) — The storage mode of file
  - Allowed values: `import`, `export`
- `expiredAt` (datetime, optional) — Date the file was expired
- `workbookId` (string, optional) — Workbook ID
- `sheetId` (string, optional) — Sheet ID
- `actions` (list of Action, optional)
- `origin` (enum, optional)
  - Allowed values: `filesystem`, `googledrive`, `box`, `onedrive`
- `treatments` (list of enum, optional)
  - Allowed values: `IS_BASIC_FILE_SHAPE`, `IS_COMPLEX_FILE_SHAPE`

### Error

- `message` (string, required)
- `key` (string, optional)

### Action

- `label` (string, required) — The text on the Button itself
- `confirm` (boolean, optional) — Whether to show a modal to confirm the action
- `constraints` (list of ActionConstraint, optional) — A limitation or restriction on the action.
- `createdFrom` (string, optional) — The action that this action was cloned from
- `deletedAt` (datetime, optional) — The time this action was deleted
- `description` (string, optional) — The text that appears in the dialog after the action is clicked.
- `guardrail` (Guardrail, optional)
- `guide` (Guide, optional)
- `icon` (string, optional) — Icon will work on primary actions. It will only accept an already existing Flatfile design system icon.
- `inputForm` (InputForm, optional) — Adds an input form for this action after it is clicked.
- `invalidConditionalMessaging` (boolean, optional) — When enabled, shows dynamic confirmation messages based on record validation status instead of the static description
- `invalidRecordsMessage` (string, optional) — Custom message to show when there are invalid records (only used when invalidConditionalMessaging is true)
- `lastPropagatedAt` (datetime, optional) — The last time this action was propagated to a workbook
- `messages` (list of ActionMessage, optional)
- `mode` (enum, optional) — Foreground and toolbarBlocking action mode will prevent interacting with the resource until complete
  - Allowed values: `foreground`, `background`, `toolbarBlocking`
- `mount` (ActionMount, optional)
- `operation` (string, optional) — This will become the job operation that is triggered
- `primary` (boolean, optional) — A primary action will be more visibly present, whether in Sheet or Workbook.
- `schedule` (enum, optional) — Determines if the action should happen on a regular cadence.
  - Allowed values: `weekly`, `daily`, `hourly`
- `tooltip` (string, optional) — A tooltip that appears when hovering the action button
- `type` (string, optional) — **This is deprecated.**
- `validRecordsMessage` (string, optional) — Custom message to show when all records are valid (only used when invalidConditionalMessaging is true)
- `requireAllValid` (boolean, optional, deprecated) — **This is deprecated. Use `constraints` instead.**
- `requireSelection` (boolean, optional, deprecated) — **This is deprecated. Use `constraints` instead.**
- `slug` (string, optional, deprecated) — **This is deprecated. Use `operation` instead.**

### ActionConstraint

- `type`: `hasAllValid`
  - `ignoreSelection` (boolean, optional)
- `type`: `hasSelection`
- `type`: `hasData`
- `type`: `hasColumnEnabled`

### Guardrail

- `content` (string, required) — Markdown guardrail for this action

### Guide

- `content` (string, required) — Markdown guidance for this action

### InputForm

- `type` (enum, required)
  - Allowed values: `simple`
- `fields` (list of InputField, required)

### ActionMessage

- `type` (enum, required)
  - Allowed values: `error`, `info`
- `content` (string, required)

### ActionMount

- `type`: `sheet`
  - `slugs` (list of string, optional)
- `type`: `workbook`
  - `slugs` (list of string, optional)
- `type`: `field`
  - `keys` (list of string, optional)
- `type`: `document`
- `type`: `file`

### InputField

- `key` (string, required) — Unique key for a Field.
- `label` (string, required) — Visible name of a Field.
- `type` (string, required) — Field Types inform the user interface how to sort and display data.
- `description` (string, optional) — Brief description below the name of the Field.
- `defaultValue` (any, optional) — Default value for a Field.
- `config` (InputConfig, optional) — Additional configuration for enum Fields.
- `constraints` (list of InputConstraint, optional) — Indicate additional validations that will be applied to the Field.

### InputConfig

- `options` (list of InputEnumPropertyOption, required)

### InputConstraint

- `type` (enum, required)
  - Allowed values: `required`

### InputEnumPropertyOption

- `value` (any, required) — The value or ID of this option. This value will be sent in egress. The type is a string | integer | boolean.
- `label` (string, optional) — A visual label for this option, defaults to value if not provided
- `description` (string, optional) — A short description for this option
- `color` (string, optional) — An optional color to assign this option
- `icon` (string, optional) — A reference pointer to a previously registered icon
- `meta` (map from string to any, optional) — An arbitrary JSON object to be associated with this option and made available to hooks

## Examples

**Request**

```json
{
  "spaceId": "string",
  "environmentId": "string",
  "file": "<file: <filename1>>"
}
```

**Response**

```json
{
  "data": {
    "id": "string",
    "name": "string",
    "ext": "string",
    "mimetype": "string",
    "encoding": "string",
    "status": "partial",
    "size": 0,
    "bytesReceived": 0,
    "createdAt": "2023-01-01T00:00:00Z",
    "updatedAt": "2023-01-01T00:00:00Z",
    "spaceId": "string",
    "description": "string",
    "mode": "import",
    "expiredAt": "2023-01-01T00:00:00Z",
    "workbookId": "string",
    "sheetId": "string",
    "actions": [
      {
        "label": "string",
        "confirm": true,
        "constraints": [
          {
            "type": "hasAllValid",
            "ignoreSelection": true
          }
        ],
        "createdFrom": "string",
        "deletedAt": "2023-01-01T00:00:00Z",
        "description": "string",
        "guardrail": {
          "content": "string"
        },
        "guide": {
          "content": "string"
        },
        "icon": "string",
        "inputForm": {
          "type": "simple",
          "fields": [
            {
              "key": "string",
              "label": "string",
              "type": "string",
              "description": "string",
              "defaultValue": {},
              "config": {
                "options": [
                  {
                    "value": {},
                    "label": "string",
                    "description": "string",
                    "color": "string",
                    "icon": "string",
                    "meta": {
                      "string": {}
                    }
                  }
                ]
              },
              "constraints": [
                {
                  "type": "required"
                }
              ]
            }
          ]
        },
        "invalidConditionalMessaging": true,
        "invalidRecordsMessage": "string",
        "lastPropagatedAt": "2023-01-01T00:00:00Z",
        "messages": [
          {
            "type": "error",
            "content": "string"
          }
        ],
        "mode": "foreground",
        "mount": {
          "type": "sheet",
          "slugs": [
            "string"
          ]
        },
        "operation": "string",
        "primary": true,
        "schedule": "weekly",
        "tooltip": "string",
        "type": "string",
        "validRecordsMessage": "string",
        "requireAllValid": true,
        "requireSelection": true,
        "slug": "string"
      }
    ],
    "origin": "filesystem",
    "treatments": [
      "IS_BASIC_FILE_SHAPE"
    ]
  }
}
```

**SDK Code**

```python
import requests

url = "https://api.x.flatfile.com/v1/files"

files = { "file": "open('<filename1>', 'rb')" }
payload = {
    "spaceId": "string",
    "environmentId": "string",
    "mode": ,
    "actions": ,
    "origin": 
}
headers = {
    "X-Disable-Hooks": "true",
    "Authorization": "Bearer <token>"
}

response = requests.post(url, data=payload, files=files, headers=headers)

print(response.json())
```

```javascript
const url = 'https://api.x.flatfile.com/v1/files';
const form = new FormData();
form.append('spaceId', 'string');
form.append('environmentId', 'string');
form.append('mode', '');
form.append('file', '<filename1>');
form.append('actions', '');
form.append('origin', '');

const options = {
  method: 'POST',
  headers: {'X-Disable-Hooks': 'true', Authorization: 'Bearer <token>'}
};

options.body = form;

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.x.flatfile.com/v1/files"

	payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"spaceId\"\r\n\r\nstring\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"environmentId\"\r\n\r\nstring\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"mode\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"<filename1>\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"actions\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"origin\"\r\n\r\n\r\n-----011000010111000001101001--\r\n")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("X-Disable-Hooks", "true")
	req.Header.Add("Authorization", "Bearer <token>")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api.x.flatfile.com/v1/files")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["X-Disable-Hooks"] = 'true'
request["Authorization"] = 'Bearer <token>'
request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"spaceId\"\r\n\r\nstring\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"environmentId\"\r\n\r\nstring\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"mode\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"<filename1>\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"actions\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"origin\"\r\n\r\n\r\n-----011000010111000001101001--\r\n"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.x.flatfile.com/v1/files")
  .header("X-Disable-Hooks", "true")
  .header("Authorization", "Bearer <token>")
  .body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"spaceId\"\r\n\r\nstring\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"environmentId\"\r\n\r\nstring\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"mode\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"<filename1>\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"actions\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"origin\"\r\n\r\n\r\n-----011000010111000001101001--\r\n")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.x.flatfile.com/v1/files', [
  'multipart' => [
    [
        'name' => 'spaceId',
        'contents' => 'string'
    ],
    [
        'name' => 'environmentId',
        'contents' => 'string'
    ],
    [
        'name' => 'file',
        'filename' => '<filename1>',
        'contents' => null
    ]
  ]
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'X-Disable-Hooks' => 'true',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.x.flatfile.com/v1/files");
var request = new RestRequest(Method.POST);
request.AddHeader("X-Disable-Hooks", "true");
request.AddHeader("Authorization", "Bearer <token>");
request.AddParameter("undefined", "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"spaceId\"\r\n\r\nstring\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"environmentId\"\r\n\r\nstring\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"mode\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"<filename1>\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"actions\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"origin\"\r\n\r\n\r\n-----011000010111000001101001--\r\n", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "X-Disable-Hooks": "true",
  "Authorization": "Bearer <token>"
]
let parameters = [
  [
    "name": "spaceId",
    "value": "string"
  ],
  [
    "name": "environmentId",
    "value": "string"
  ],
  [
    "name": "mode",
    "value": 
  ],
  [
    "name": "file",
    "fileName": "<filename1>"
  ],
  [
    "name": "actions",
    "value": 
  ],
  [
    "name": "origin",
    "value": 
  ]
]

let boundary = "---011000010111000001101001"

var body = ""
var error: NSError? = nil
for param in parameters {
  let paramName = param["name"]!
  body += "--\(boundary)\r\n"
  body += "Content-Disposition:form-data; name=\"\(paramName)\""
  if let filename = param["fileName"] {
    let contentType = param["content-type"]!
    let fileContent = String(contentsOfFile: filename, encoding: String.Encoding.utf8)
    if (error != nil) {
      print(error as Any)
    }
    body += "; filename=\"\(filename)\"\r\n"
    body += "Content-Type: \(contentType)\r\n\r\n"
    body += fileContent
  } else if let paramValue = param["value"] {
    body += "\r\n\r\n\(paramValue)"
  }
}

let request = NSMutableURLRequest(url: NSURL(string: "https://api.x.flatfile.com/v1/files")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```