# Images and video

> Page: https://docs.flung.dev/media. Index of every page: https://docs.flung.dev/llms.txt

Attach images or a video to a post: upload the file, or let Flung fetch it from a link, then pass its id in `mediaIds`.

## TL;DR

| Question | Answer |
|---|---|
| Which files? | JPEG, PNG and WebP up to 20 MB, GIF up to 15 MB, and MP4 and QuickTime up to 1 GB. Flung reads the real type from the file itself. |
| How do I upload? | Reserve the file, send its bytes, and use it once it is `ready`. Files over 100 MB go in parts. The SDK does all of it in one call. |
| Can Flung fetch a file from a link? | Yes: import it from a public https address. |
| Does a video get a thumbnail? | Yes, a frame one second in, for showing beside the file. Posts never wait for it. |

## Upload with the SDK

```ts
const image = await flung.uploadMedia(await readFile('launch.png'), { contentType: 'image/png', filename: 'launch.png' })
await flung.posts.create({ content: 'Launching today.', accountIds, mediaIds: [image.id] })
```

## Import from a link

**curl**

```bash
curl -X POST 'https://api.flung.dev/v1/media/import' \
  --header "Authorization: Bearer $FLUNG_API_KEY" \
  --header 'Content-Type: application/json' \
  --header "Idempotency-Key: $(uuidgen)" \
  --data '{
  "url": "https://example.com/launch.jpg"
}'
```

**TypeScript**

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

const flung = new Flung({ apiKey: process.env.FLUNG_API_KEY! })
const result = await flung.media.import({
  url: 'https://example.com/launch.jpg',
})
```

**fetch**

```js
const response = await fetch('https://api.flung.dev/v1/media/import', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${process.env.FLUNG_API_KEY}`,
    'Content-Type': 'application/json',
    'Idempotency-Key': crypto.randomUUID(),
  },
  body: JSON.stringify({
    url: 'https://example.com/launch.jpg',
  }),
})
if (!response.ok) throw new Error((await response.json()).error.message)
const result = await response.json()
```

## What each platform takes

Each platform's own limits apply on top of Flung's, such as Bluesky's 1 MB images or X's four images a post. [List platforms](https://docs.flung.dev/reference/api/get-v1-platforms.md) gives every limit, and a post a platform cannot carry is refused when you create it.
