# Upload Object

`POST /storage/buckets/{bucketName}/objects` · Core · Storage & Schema

Uploads one object into the bucket as `multipart/form-data`. Fields:
- `file` (the bytes).
- `path` (where the object goes in the bucket; it may contain slashes).
- Optional `contentType`.
- Optional `upsert` (`"true"` replaces an object already at that path).
- Optional `metadata`, a flat JSON object of string values stored with the object.

Answers 201 with the stored object. Needs upload rights on the bucket; in a `custom` bucket the bucket's storage policy decides, and replacing an existing object with `upsert` also needs the policy's delete grant. The upload is audited as `data.write.storage.object.created` with the bucket, size and content type.

## Parameters

| Name | In | Required | Description |
|---|---|---|---|
| `bucketName` | path | yes | The bucket's name. It is unique within the project. Example: `"product-images"`. |
| `projectSlug` | path | yes | The project's slug: the path segment after `@`. It is unique within the org. Example: `"storefront"`. |

## Request body

| Field | Type | Required | Description |
|---|---|---|---|
| `file` | string (binary) | yes | The object's bytes. Its part's content type is used when `contentType` is omitted. |
| `path` | string | yes | Where the object goes in the bucket. It may contain slashes to group objects under a prefix. Example: `"users/u_42/avatar.png"`. |
| `contentType` | string | no | The object's MIME type. Omitted, the `file` part's own content type is used. The bucket's allowed MIME types apply to it. Example: `"image/png"`. |
| `upsert` | enum ("true", "false") | no | `true` replaces an object already at `path`. Omitted or any other value, an upload to a path that holds an object is refused. Example: `"true"`. |
| `metadata` | string | no | A JSON object of string values stored with the object, sent as JSON text. Custom storage policies can read it as `metadata`. Example: `"{\"owner\":\"u_42\",\"source\":\"profile-page\"}"`. |

## Responses

- **201**: The object was written.

| Field | Type | Required | Description |
|---|---|---|---|
| `data` | object | yes | The stored object. |
| `data.path` | string | yes | The object's path in the bucket, as sent. Example: `"users/u_42/avatar.png"`. |
| `data.size` | integer | yes | The object's size in bytes. Example: `48213`. |
| `data.lastModified` | string (date-time) \| null | yes | Null from the platform-managed and customer storage locations, which don't report a write time on upload. Example: `null`. |
| `meta` | object | yes | Request metadata: cost, timing and correlation ids. |


## Errors

| HTTP | Code | When |
|---|---|---|
| 401 | `K9O_UNAUTHENTICATED` | Authentication is required. |
| 403 | `K9O_RBAC_DENY` | The caller's project role does not permit this object operation. |
| 404 | `K9O_BUCKET_NOT_FOUND` | No bucket with this name exists in the project. |
| 400 | `K9O_INVALID_FIELD_VALUE` | The object violates a bucket constraint (file-size limit, allowed MIME type, or metadata cap) or the metadata is malformed. |
| 409 | `K9O_ALREADY_EXISTS` | An object already exists at this path and upsert is false. |
| 422 | `K9O_MALWARE_DETECTED` | The uploaded object was quarantined by malware scanning and not stored. |
| 403 | `K9O_ACCESS_DENIED` | The bucket's storage policy does not allow upload for this caller (context.reason storage_policy_denied). Checked after the role and IAM checks; a bucket with no policy is unaffected. |

## Code samples

### cURL

```bash
curl -X POST 'https://<org>.api-<region>.k9o.io/@storefront/storage/buckets/product-images/objects' \
  -H 'Authorization: Bearer $K9O_TOKEN'
```

### fetch

```javascript
const res = await fetch('https://<org>.api-<region>.k9o.io/@storefront/storage/buckets/product-images/objects', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${process.env.K9O_TOKEN}`
  },
});
const { data, meta } = await res.json();
```

### @k9o/core

```typescript
// const k9o = new K9o({ orgSlug: 'playground', projectSlug: 'storefront', apiKey: 'k9o_…' })
const { data } = await k9o.from('<collection>').upload()
```

### k9o

```python
# k9o = create_client(org_slug="playground", project_slug="storefront", api_key="k9o_…")
response = k9o.from_("<collection>").upload()
```

### sdk-go

```go
// ctx := context.Background()
// client, _ := k9o.NewClient(k9o.ClientOpts{OrgSlug: "playground", ProjectSlug: "storefront", APIKey: "k9o_…"})
data, _, kerr := client.From("<collection>").Upload()
```

### k9o

```rust
// let k9o = Client::new(ClientOpts { org_slug: "playground".into(), project_slug: "storefront".into(), api_key: "k9o_…".into() })?;
let resp = k9o.from("<collection>").upload().await?
```

### dev.k9o:core

```java
// K9o k9o = K9o.createClient(K9o.Opts.builder().orgSlug("playground").projectSlug("storefront").apiKey("k9o_…").build());
var response = k9o.from("<collection>").upload()
```

### K9o.Core

```c#
// var k9o = K9oClient.Create(new K9oOptions { OrgSlug = "playground", ProjectSlug = "storefront", ApiKey = "k9o_…" });
var response = await k9o.From("<collection>").UploadAsync()
```

### k9o

```ruby
# k9o = K9o.create_client(org_slug: "playground", project_slug: "storefront", api_key: "k9o_…")
response = k9o.from("<collection>").upload()
```

### k9o/sdk

```php
// $k9o = K9oClient::create(['org_slug' => 'playground', 'project_slug' => 'storefront', 'api_key' => 'k9o_…']);
$response = $k9o->from('<collection>')->upload()
```

### K9o

```swift
// let k9o = try K9o.createClient(orgSlug: "playground", projectSlug: "storefront", apiKey: "k9o_…")
let result = try await k9o.from("<collection>").upload()
```

### core-kotlin

```kotlin
// val k9o = createClient { orgSlug = "playground"; projectSlug = "storefront"; apiKey = "k9o_…" }
val result = k9o.from("<collection>").upload()
```

### k9o (Flutter)

```dart
// final k9o = K9o.createClient(orgSlug: 'playground', projectSlug: 'storefront', apiKey: 'k9o_…');
final result = await k9o.from('<collection>').upload()
```

### @k9o/react-native

```javascript
// const k9o = createClient({ orgSlug: 'playground', projectSlug: 'storefront', apiKey: 'k9o_…' })  // RN, secure storage
const { data } = await k9o.from('<collection>').upload()
```


Canonical page: https://docs.kilimanjaro.dev/api-playground/core/upload-object
