Skip to content
OpenPostDocs
OpenPostDocs

Upload media

Upload files safely with the TypeScript SDK and attach them to Publications.

media.upload() handles the OpenPost upload-session flow. It reserves the media record, sends the bytes to the returned storage target, and completes the record.

const bytes = new Uint8Array(await Bun.file("cover.png").arrayBuffer());

const asset = await openpost.media.upload({
  workspaceId: openpost.workspaceId(),
  file: bytes,
  filename: "cover.png",
  mimeType: "image/png",
  altText: "Product import screen with the completed file list",
});

External storage targets receive only the upload headers returned by OpenPost. The SDK never sends your OpenPost bearer token to another origin.

Attach the returned ID when you create a Publication:

const draft = await openpost.publications.create({
  workspace_id: openpost.workspaceId(),
  title: "Import walkthrough",
  content_profile: "image_post",
  source_text: "The new import flow is live.",
  social_account_ids: ["acc_linkedin"],
  media: [
    {
      media_id: asset.id,
      alt_text: "Product import screen with the completed file list",
    },
  ],
});

Use media.list(workspaceId) to inspect the library and media.remove(id) to remove an unused item. OpenPost still applies workspace quotas, file validation, provider limits, and media processing after the bytes arrive.