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

# Create Encrypted File Upload

POST https://www.konfidant.app/api/v1/files
Content-Type: application/json

Step 1 of a file share. Reserves an upload slot for exactly `ciphertext_size` bytes of KNF1 ciphertext and returns a presigned URL. Step 2: `PUT` the ciphertext to `upload_url` with exactly `upload_headers`. Step 3: call `POST /api/v1/files/{fileKey}/complete` to receive the download URL. The file name and MIME type are encrypted inside the ciphertext and never sent in plaintext.

Reference: https://docs.konfidant.app/konfidant-api/create-file-upload

## Authentication

- `Authorization` header (bearer token, required) — Konfidant API key (`kf_live_...` or `kf_test_...`), created by an organization admin in the dashboard.

## Request

### Body (application/json)

This endpoint expects an object.

- `ciphertext_size` (integer, required) — Exact size in bytes of the KNF1 ciphertext that will be uploaded. Checked against the plan's file size limit (allowing for KNF1 overhead) and the monthly storage quota.
- `ttl_hours` (integer, optional) — Lifetime of the share link in hours. Optional; defaults to the maximum allowed by the organization's plan. Values above the plan maximum are rejected with 400.

## Response

### 201

Created

- `upload_url` (string, required) — Presigned URL for a single `PUT` of the ciphertext. Do not send your API key to it.
- `file_key` (string, required) — Identifier of the upload; pass it to the complete endpoint.
- `upload_headers` (map from string to string, required) — Headers that must be sent with the `PUT`, exactly as returned.
- `upload_expires_in` (integer, required) — Seconds until `upload_url` expires.

## Errors

### 400 Bad Request Error

Bad Request: invalid JSON, invalid `ciphertext_size`, file above plan limit, or TTL above plan maximum

- `error` (string, required)

### 401 Unauthorized Error

Unauthorized

- `error` (string, required)

### 403 Forbidden Error

Forbidden: missing scope, plan without API access, or quota exceeded

- `error` (string, required)
- `code` (string, optional) — `api_quota_exceeded` when the organization's API share allowance is used up.
- `required_scope` (string, optional)
- `available_scopes` (list of string, optional)

### 429 Too Many Requests Error

Rate limit exceeded

- `error` (string, required)
- `limit` (integer, optional)
- `window_seconds` (integer, optional)
- `retry_after_seconds` (integer, optional)

## Examples

**Request**

```json
{
  "ciphertext_size": 1048720,
  "ttl_hours": 48
}
```

**Response**

```json
{
  "upload_url": "https://<account>.r2.cloudflarestorage.com/encrypted-eu/3f9a...c2?X-Amz-Algorithm=AWS4-HMAC-SHA256&...",
  "file_key": "3f9a0c5e7b1d2a4f6e8c0b9d7a5f3e1c2b4d6f8a0e9c7b5d3f1a2c4e6b8d0f9a",
  "upload_headers": {
    "Content-Type": "application/octet-stream"
  },
  "upload_expires_in": 3600
}
```

**SDK Code**

```python createFileUpload_example
import requests

url = "https://www.konfidant.app/api/v1/files"

payload = {
    "ciphertext_size": 1048720,
    "ttl_hours": 48
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript createFileUpload_example
const url = 'https://www.konfidant.app/api/v1/files';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"ciphertext_size":1048720,"ttl_hours":48}'
};

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

```go createFileUpload_example
package main

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

func main() {

	url := "https://www.konfidant.app/api/v1/files"

	payload := strings.NewReader("{\n  \"ciphertext_size\": 1048720,\n  \"ttl_hours\": 48\n}")

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

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

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

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

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

}
```

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

url = URI("https://www.konfidant.app/api/v1/files")

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

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"ciphertext_size\": 1048720,\n  \"ttl_hours\": 48\n}"

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

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

HttpResponse<String> response = Unirest.post("https://www.konfidant.app/api/v1/files")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"ciphertext_size\": 1048720,\n  \"ttl_hours\": 48\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://www.konfidant.app/api/v1/files', [
  'body' => '{
  "ciphertext_size": 1048720,
  "ttl_hours": 48
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp createFileUpload_example
using RestSharp;

var client = new RestClient("https://www.konfidant.app/api/v1/files");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"ciphertext_size\": 1048720,\n  \"ttl_hours\": 48\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift createFileUpload_example
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "ciphertext_size": 1048720,
  "ttl_hours": 48
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://www.konfidant.app/api/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()
```