# Media Uploads

> Upload images and PDFs through the REST API into the WordPress media library and attach them to entries.

- **Category:** REST API
- **Canonical Guide:** https://pottr.tangble.com/docs/media-uploads

---

>
Upload images and PDFs through the REST API into the WordPress media library and attach them to entries.

## Upload a File

POST
/media
Public or Secret Key

Send the file as `multipart/form-data` (field name `file`) or as JSON with a base64 data URL. Identify your app with the `X-Pottr-App` header or an `app` parameter. Add `X-Pottr-User-Token` to record the signed-in user as the owner.

**File: `upload.js`**

```javascript
const form = new FormData();
form.append('file', fileInput.files[0]);

const res = await fetch('https://example.com/wp-json/pottr/v1/media', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${PUBLIC_KEY}`,
    'X-Pottr-App': 'task-manager',
    'X-Pottr-User-Token': userAccessToken
  },
  body: form
});

const media = await res.json(); // use media.id in a `media` field
```

## Attach It to an Entry

Add a field of type `media` to your collection and store the attachment ID in it. The field also accepts the object returned by the upload or a media URL.

## What Is Accepted

<ul>
<li>**Types:** JPEG, PNG, WebP, GIF, SVG and PDF.</li>
<li>**Size:** 10 MB on Free, 25 MB on Pro, 50 MB on Business. Larger files return `413`.</li>
<li>**Executable extensions** (such as `.php`, `.exe`, `.sh`, `.js`) and multi-extension names are rejected with `400`.</li>
<li>**SVG files** are parsed and rejected if they contain scripts, event handlers, external references, entities or `foreignObject`, or exceed 2 MB (`invalid_file_type`).</li>
</ul>

Files are stored under `wp-content/uploads/pottr/{app}/{year}/{month}/` with unguessable names and are registered in the WordPress media library.

## Delete a File

DELETE
/media/&#123;id&#125;
Owner or Secret Key

Only the user who uploaded the file, or a secret key, can delete it.
