Pottr/Docs
Topic:Media Uploads
REST API
.md

Media Uploads

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

Upload a File

POST/mediaPublic 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.

upload.js
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

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

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/{id}Owner or Secret Key

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