Media

Create Media

Creates a media asset and returns uploadUrl. PUT the file to uploadUrl with the declared Content-Type and exactly size bytes, then use the asset's id in a post. Files are kept for 7 days until a post uses them.

POST
/v1/media

Authorization

Bearer
headerAuthorizationBearer <op_>

Workspace API key, sent as Authorization: Bearer op_... Keys are created in the dashboard.

Header Parameters

Idempotency-Key?string

A unique key, such as a UUID, that makes retrying this request safe. A repeat with the same key and body within 24 hours returns the first response instead of acting again. A 429 or 5xx response is not kept, so a retry with the same key runs again.

Length1 <= length <= 255

Request Body

application/json
  1. body
filename*string

Name of the file you will upload.

Length1 <= length <= 255
contentType*string

MIME type of the file. Send the same value as the Content-Type header of the upload.

Length1 <= length <= 127
size*integer

Exact size of the file in bytes. The upload must be exactly this many bytes, and within the size limit for contentType.

Range0 < value <= 1073741824

Response Body

Media asset waiting for its upload

application/json
  1. response
id*string

Pass it in a post's media as { id }.

url*string

Public URL of the file. It never changes, and serves the file once status is ready.

Formaturi
contentType*string

MIME type of the file.

sizeBytes*|

File size in bytes. Null until status is ready.

filename*|

The filename sent to Create Media. Null for a file added without one.

status*|

pending until the file has been uploaded to uploadUrl and checked, usually within seconds. New values can be added, so handle a value you do not know.

createdAt*string
Formatdate-time
uploadUrl*string

Upload the file here with a PUT request, the declared Content-Type and exactly size bytes. No API key is needed for the upload.

Formaturi
uploadExpiresIn*integer

Seconds until uploadUrl expires.

Example Request
import { Configuration, MediaApi } from "@onepostly/sdk";const mediaApi = new MediaApi(  new Configuration({ accessToken: process.env.ONEPOSTLY_API_KEY }));const response = await mediaApi.createMedia({  createMediaBody: {    "filename": "launch.mp4",    "contentType": "video/mp4",    "size": 48203776  },});console.log(response);
Example Response
{  "id": "med_7f3a9c2e1b4d4e8f9a6b5c4d3e2f1a0b",  "url": "https://cdn.onepostly.com/media/5b0e7c1a-2f4d-4c8e-9a3b-6d1f0e2c4a7b/7f3a9c2e-1b4d-4e8f-9a6b-5c4d3e2f1a0b.mp4",  "contentType": "video/mp4",  "sizeBytes": null,  "filename": "launch.mp4",  "status": "pending",  "createdAt": "2027-03-15T09:00:00.000Z",  "uploadUrl": "https://5d1e8a3c9f2b4e7a.r2.cloudflarestorage.com/onepostly-media/temp/5b0e7c1a-2f4d-4c8e-9a3b-6d1f0e2c4a7b/7f3a9c2e-1b4d-4e8f-9a6b-5c4d3e2f1a0b.mp4?X-Amz-Expires=3600&X-Amz-Date=20270315T090000Z&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=EXAMPLEKEY%2F20270315%2Fauto%2Fs3%2Faws4_request&X-Amz-SignedHeaders=content-length%3Bcontent-type%3Bhost&X-Amz-Signature=0f4c2b9e7a1d3f5b8c6e0a2d4f6b8e1c3a5d7f9b2e4c6a8d0f1b3e5c7a9d2f4b",  "uploadExpiresIn": 3600}