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

# Create or overwrite file

PUT https://aihub.instabase.com/api/v2/files/{path}
Content-Type: application/octet-stream

Create a non-empty file or overwrite an existing file.If the parent folder of the `path` parameter doesn't exist, the file system creates it before creating the file.This acts on files in the AI Hub filesystem, not your local filesystem.Ensure the path is accessible within the context defined by the `IB-Context` header.Not all filesystem types support this operation.| Filesystem           | Supported |
| -------------------- | --------- |
| Instabase            | ✓         |
| Amazon S3            | ✓         |
| Azure Blob Storage   | ✓         |
| Google Cloud Storage | ✓         |
| Google Drive         | -         |

Reference: https://docs.instabase.com/api-sdk/api-reference/files/write-file

## Authentication

- `Authorization` header (bearer token, required) — Bearer HTTP authentication.

## Request

### Path parameters

- `path` (string, required) — Full path to the file.

### Headers

- `IB-Context` (string, optional) — Typically your organization ID. See [Authorization and context identification](/api-sdk/authorization#ib-context-header) for details.

### Body (application/octet-stream)

This endpoint expects binary data of type application/octet-stream.

- Binary request body.

## Response

### 201

The request succeeded and a new file was created at the target location. AI Hub returns this status code only when the request includes an `If-None-Match` header with a value of `*`.

## Errors

### 412 Precondition Failed Error

The request failed because a file exists at the target location that matches the `If-None-Match` header.

- `any`

## Examples

**Request**

```json
"SGVsbG8gdGhpcyBpcyBhIHRlc3QgZmlsZSBjb250ZW50Lg=="
```

**Response**

```json
{}
```

**SDK Code**

```python with SDK
from aihub import AIHub

client = AIHub(
    api_root="https://aihub.instabase.com/api",
    api_key="abcdefghijklmnopqrst1234567890",
    ib_context="john.doe_acme.com"
)

organization_id = "acme_org"
workspace = "MyWorkspace"
drive = "MyDrive"
folder = "MyFolder"
file_name = "hello.txt"
file_path = f"{organization_id}/{workspace}/fs/{drive}/{folder}/{file_name}"
file_contents = bytes("Hello world", "utf-8")

# returns None
client.files.write(path=file_path, data=file_contents)

```

```python without SDK
import requests

organization_id = "acme_org"
workspace = "MyWorkspace"
drive = "MyDrive"
folder = "MyFolder"
file_name = "hello.txt"
file_path = f"{organization_id}/{workspace}/fs/{drive}/{folder}/{file_name}"
file_contents = bytes("Hello world", "utf-8")

url = f"https://aihub.instabase.com/api/v2/files/{file_path}"

headers = {
    "Authorization": "Bearer abcdefghijklmnopqrst1234567890",
    "IB-Context": "john.doe_acme.com",
    "Content-Type": "application/octet-stream"
}

# make the PUT request
response = requests.put(url, headers=headers, data=file_contents)

# handle the response
if response.status_code in [201, 204]:
    print("File written successfully")
else:
    print(f"Error: {response.status_code} - {response.text}")

```

```javascript
const url = 'https://aihub.instabase.com/api/v2/files/path';
const options = {
  method: 'PUT',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/octet-stream'},
  body: '"SGVsbG8gdGhpcyBpcyBhIHRlc3QgZmlsZSBjb250ZW50Lg=="'
};

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://aihub.instabase.com/api/v2/files/path"

	payload := strings.NewReader("\"SGVsbG8gdGhpcyBpcyBhIHRlc3QgZmlsZSBjb250ZW50Lg==\"")

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

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

	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://aihub.instabase.com/api/v2/files/path")

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

request = Net::HTTP::Put.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/octet-stream'
request.body = "\"SGVsbG8gdGhpcyBpcyBhIHRlc3QgZmlsZSBjb250ZW50Lg==\""

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.put("https://aihub.instabase.com/api/v2/files/path")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/octet-stream")
  .body("\"SGVsbG8gdGhpcyBpcyBhIHRlc3QgZmlsZSBjb250ZW50Lg==\"")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('PUT', 'https://aihub.instabase.com/api/v2/files/path', [
  'body' => '"SGVsbG8gdGhpcyBpcyBhIHRlc3QgZmlsZSBjb250ZW50Lg=="',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/octet-stream',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://aihub.instabase.com/api/v2/files/path");
var request = new RestRequest(Method.PUT);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/octet-stream");
request.AddParameter("application/octet-stream", "\"SGVsbG8gdGhpcyBpcyBhIHRlc3QgZmlsZSBjb250ZW50Lg==\"", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/octet-stream"
]

let postData = NSData(data: ""SGVsbG8gdGhpcyBpcyBhIHRlc3QgZmlsZSBjb250ZW50Lg=="".data(using: String.Encoding.utf8)!)

let request = NSMutableURLRequest(url: NSURL(string: "https://aihub.instabase.com/api/v2/files/path")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "PUT"
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()
```