Skip to main content

Endpoint

POST https://api.ugc.inc/media/create/url

Overview

This endpoint generates a short-lived Vercel Blob client token for direct uploads. Upload the file with the returned pathname and clientToken, then call /media/create to register the uploaded blob as media in your organization. Upload flow:
  1. Call /media/create/url with the filename and optional MIME type
  2. Upload the file directly to Vercel Blob using put(pathname, file, { token: clientToken })
  3. Call /media/create with the uploaded blob URL to create the media record

Request Body

filename
string
required
Original filename. The API prefixes the stored path with your organization ID and adds a random suffix to avoid collisions.
contentType
string
Optional MIME type (for example image/jpeg or video/mp4). When omitted, the token allows image, video, and audio uploads.

Response

data
UploadTokenResponse
Upload token payload

TypeScript

import { put } from "@vercel/blob/client";
import { UGCClient } from "ugcinc";

const client = new UGCClient({
  apiKey: "YOUR_API_KEY",
});

async function uploadFile(file: File, tag?: string) {
  const tokenResponse = await client.media.getUploadToken({
    filename: file.name,
    contentType: file.type || undefined,
  });

  if (!tokenResponse.ok) {
    throw new Error(tokenResponse.message);
  }

  const blob = await put(tokenResponse.data.pathname, file, {
    access: "public",
    token: tokenResponse.data.clientToken,
  });

  const mediaResponse = await client.media.create({
    urls: [blob.url],
    tag,
  });

  if (!mediaResponse.ok) {
    throw new Error(mediaResponse.message);
  }

  return mediaResponse.data.data[0];
}
{
  "ok": true,
  "code": 200,
  "message": "Success",
  "data": {
    "clientToken": "vercel_blob_client_...",
    "pathname": "media/org_123/example.mp4"
  }
}