> Toden documentation. For the full index fetch /llms.txt. Every page is available as Markdown by appending .md to its URL. Identity verification uses /api/kyc, Risk Intelligence uses /api/v1; they are separate contracts with different error shapes. Never invent an endpoint, field or enum value: read the API reference page for the operation first.

# Upload a capture file

POST https://sandbox-api.toden.co/api/kyc/upload
Content-Type: multipart/form-data

Stores one document image, selfie, video or supporting file and returns its `mediaId`, which you then reference when creating a verification. An unreferenced upload is discarded after 30 minutes.

Accepted content types are `image/jpeg`, `image/png`, `image/webp`, `video/webm`, `video/mp4` and `application/pdf`. The file content decides the stored type, so a HEIC photo labelled as JPEG is converted for you.

A hosted verification session token is also accepted in place of an API key. An optional `X-Myaza-Device-Id` header (at most 64 characters) records which device made the capture.

This endpoint returns plain sentences in `error` rather than stable codes, apart from the authentication codes below.

**Error codes**

| `error` | Status | Meaning |
|---|---|---|
| `type must be one of ...` | 400 | The `type` field is missing or not an accepted value. |
| `file is required` | 400 | No `file` part was sent. |
| `mimeType one of ...` | 400 | The file content type is not accepted. |
| `File too large (max 25MB)` | 400 | The file exceeds the size limit. |
| `(storage message)` | 400 | The file could not be stored, for example a PDF sent for an image-only type. |
| `(conversion message)` | 415 | A HEIC image could not be converted. |
| `Missing or invalid Authorization header` | 401 | No bearer credential was sent. |
| `Invalid API key` | 401 | The key is unknown or revoked. |
| `environment_mismatch` | 403 | The key belongs to an environment this host does not serve. |
| `origin_not_allowed` | 403 | The request origin is not on the publishable key allowlist. |
| `ip_not_allowed` | 403 | The caller address is not on the secret key allowlist. |
| `organization_suspended` | 403 | The organisation is suspended. |
| `business_not_approved` | 403 | A production key was used before the business was approved. |

Accepts a publishable (`pk_`) or secret (`sk_`) key.

Reference: https://docs.toden.co/api-reference/verification/media/upload-media

## Authentication

- `Authorization` header (bearer token, required) — Send the API key as a Bearer token. Each operation states whether a publishable key is enough or a secret key is required.

## Servers

- `https://sandbox-api.toden.co` (Sandbox, default)
- `https://api.toden.co` (Production)

## Request

### Body (multipart/form-data)

This endpoint expects a multipart form containing a file.

- `file` (file, required) — The raw file bytes, at most 25 MB.
- `type` (enum, required) — What the file is. Images are accepted for every type, videos for the video types, and PDF only for `proof_of_address`, `business_document` and `supporting_document`.
- `sessionId` (string, optional) — The resumable session this upload belongs to, so the file is kept for the life of that session rather than the default 30 minutes.

## Response

### 200

The file was stored.

- `mediaId` (string, required) — The identifier to reference in `mediaIds` when creating a verification.

## Errors

### 400 Bad Request Error

The request body, query or path was invalid.

- `error` (string, required) — A stable machine-readable code such as `invalid_input`. Authentication failures (401) carry a short sentence here instead of a code.
- `message` (string, optional) — A human-readable explanation, safe to log. The wording may change.

### 401 Unauthorized Error

The Authorization header is missing, or the API key is unknown or revoked.

- `error` (string, required) — A stable machine-readable code such as `invalid_input`. Authentication failures (401) carry a short sentence here instead of a code.
- `message` (string, optional) — A human-readable explanation, safe to log. The wording may change.

### 403 Forbidden Error

The key may not call this endpoint, or the organisation may not use this feature.

- `error` (string, required) — A stable machine-readable code such as `invalid_input`. Authentication failures (401) carry a short sentence here instead of a code.
- `message` (string, optional) — A human-readable explanation, safe to log. The wording may change.

### 415 Unsupported Media Type Error

The file type is not supported.

- `error` (string, required) — A stable machine-readable code such as `invalid_input`. Authentication failures (401) carry a short sentence here instead of a code.
- `message` (string, optional) — A human-readable explanation, safe to log. The wording may change.

## Examples

**Request**

```json
{
  "file": "<file: (binary)>",
  "type": "document_front"
}
```

**Response**

```json
{
  "mediaId": "med_01j9x2k4m8"
}
```

**SDK Code**

```python Media_uploadMedia_example
import requests

url = "https://sandbox-api.toden.co/api/kyc/upload"

files = { "file": "open('(binary)', 'rb')" }
payload = {
    "sessionId": ,
    "type": "document_front"
}
headers = {"Authorization": "Bearer <apiKey>"}

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

print(response.json())
```

```javascript Media_uploadMedia_example
const url = 'https://sandbox-api.toden.co/api/kyc/upload';
const form = new FormData();
form.append('file', '(binary)');
form.append('sessionId', '');
form.append('type', 'document_front');

const options = {method: 'POST', headers: {Authorization: 'Bearer <apiKey>'}};

options.body = form;

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

```go Media_uploadMedia_example
package main

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

func main() {

	url := "https://sandbox-api.toden.co/api/kyc/upload"

	payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"(binary)\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"sessionId\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"type\"\r\n\r\ndocument_front\r\n-----011000010111000001101001--\r\n")

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

	req.Header.Add("Authorization", "Bearer <apiKey>")

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

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

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

}
```

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

url = URI("https://sandbox-api.toden.co/api/kyc/upload")

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

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <apiKey>'
request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"(binary)\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"sessionId\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"type\"\r\n\r\ndocument_front\r\n-----011000010111000001101001--\r\n"

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

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

HttpResponse<String> response = Unirest.post("https://sandbox-api.toden.co/api/kyc/upload")
  .header("Authorization", "Bearer <apiKey>")
  .body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"(binary)\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"sessionId\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"type\"\r\n\r\ndocument_front\r\n-----011000010111000001101001--\r\n")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://sandbox-api.toden.co/api/kyc/upload', [
  'multipart' => [
    [
        'name' => 'file',
        'filename' => '(binary)',
        'contents' => null
    ],
    [
        'name' => 'type',
        'contents' => 'document_front'
    ]
  ]
  'headers' => [
    'Authorization' => 'Bearer <apiKey>',
  ],
]);

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

```csharp Media_uploadMedia_example
using RestSharp;

var client = new RestClient("https://sandbox-api.toden.co/api/kyc/upload");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <apiKey>");
request.AddParameter("undefined", "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"(binary)\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"sessionId\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"type\"\r\n\r\ndocument_front\r\n-----011000010111000001101001--\r\n", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Media_uploadMedia_example
import Foundation

let headers = ["Authorization": "Bearer <apiKey>"]
let parameters = [
  [
    "name": "file",
    "fileName": "(binary)"
  ],
  [
    "name": "sessionId",
    "value": 
  ],
  [
    "name": "type",
    "value": "document_front"
  ]
]

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://sandbox-api.toden.co/api/kyc/upload")! 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()
```