# Upload one part

> Page: https://docs.flung.dev/reference/api/put-v1-media-id-parts-partnumber. Index of every page: https://docs.flung.dev/llms.txt

One part of a multipart upload, as the raw body with its Content-Length.

`PUT /v1/media/{id}/parts/{partNumber}`

## TL;DR

| Question | Answer |
|---|---|
| What does it do? | Upload one part. |
| What does it need? | An API key or an OAuth access token. |
| What does it take? | `id`, `partNumber` in the path. |
| What does it return? | Status 200 with a body of type [`UploadedPart`](https://docs.flung.dev/reference/api/schemas.md#uploadedpart). |
| In the SDK? | `flung.media.uploadPart()` |
| What can go wrong? | `401` Missing, unknown, revoked or expired API key; `404` No such file in this workspace; `422` The request failed validation; `429` Too many requests for this credential; wait for `retry-after` seconds. Every failure has the same [error shape](https://docs.flung.dev/reference/api/errors.md). |

## What it does

One part of a multipart upload, as the raw body with its Content-Length. Sending a part again replaces it.

## Example

**curl**

```bash
curl -X PUT 'https://api.flung.dev/v1/media/med_aaaaaaaaaaaaaaaaaaaaaaaa/parts/1' \
  --header "Authorization: Bearer $FLUNG_API_KEY" \
  --header 'Content-Type: application/octet-stream' \
  --data-binary @launch.png
```

**TypeScript**

```ts
import { readFile } from 'node:fs/promises'

import { Flung } from '@flung.dev/sdk'

const flung = new Flung({ apiKey: process.env.FLUNG_API_KEY! })
const file = new Blob([await readFile('launch.png')], { type: 'image/png' })
const result = await flung.media.uploadPart({
  id: 'med_aaaaaaaaaaaaaaaaaaaaaaaa',
  partNumber: 1,
  body: file,
}, { headers: { 'content-length': String(file.size) } })
```

**fetch**

```js
import { readFile } from 'node:fs/promises'

const file = await readFile('launch.png')
const response = await fetch('https://api.flung.dev/v1/media/med_aaaaaaaaaaaaaaaaaaaaaaaa/parts/1', {
  method: 'PUT',
  headers: {
    'Authorization': `Bearer ${process.env.FLUNG_API_KEY}`,
    'Content-Type': 'application/octet-stream',
    'Content-Length': String(file.byteLength),
  },
  body: file,
})
if (!response.ok) throw new Error((await response.json()).error.message)
const result = await response.json()
```

A successful answer looks like this:

```json
{
  "partNumber": 1,
  "bytes": 1
}
```

## Path parameters

| Field | Type | Required | Description |
|---|---|---|---|
| `id` | `string` | yes |  |
| `partNumber` | `integer` | yes |  |

## Responses

| Status | Meaning | Body |
|---|---|---|
| 200 | The part was stored. | [`UploadedPart`](https://docs.flung.dev/reference/api/schemas.md#uploadedpart) |
| 401 | Missing, unknown, revoked or expired API key. | [`Error`](https://docs.flung.dev/reference/api/schemas.md#error) |
| 404 | No such file in this workspace. | [`Error`](https://docs.flung.dev/reference/api/schemas.md#error) |
| 422 | The request failed validation. | [`Error`](https://docs.flung.dev/reference/api/schemas.md#error) |
| 429 | Too many requests for this credential; wait for `retry-after` seconds. | [`Error`](https://docs.flung.dev/reference/api/schemas.md#error) |

## Response body

A 200 answer has the type [`UploadedPart`](https://docs.flung.dev/reference/api/schemas.md#uploadedpart).

| Field | Type | Required | Description |
|---|---|---|---|
| `partNumber` | `integer` | yes |  |
| `bytes` | `integer` | yes |  |

## See also

| Doc | Why |
|---|---|
| [API reference](https://docs.flung.dev/reference/api.md) | Every endpoint |
| [Schemas](https://docs.flung.dev/reference/api/schemas.md) | Every request and response type |
| [Errors](https://docs.flung.dev/reference/api/errors.md) | Every error code and what to do about it |
