Endpoint
POST https://api.ugc.inc/media/create/url
Overview
This endpoint is designed to be used as the handleUploadUrl for the @vercel/blob/client upload function. It handles token generation for direct client-to-storage uploads.
Upload Flow:
Client calls upload() from @vercel/blob/client with this endpoint as handleUploadUrl
This endpoint validates auth and returns upload credentials
Client uploads directly to Vercel Blob storage
After upload, call /media/create with the resulting blob URL to create the media record
Usage with @vercel/blob/client
import { upload } from '@vercel/blob/client' ;
import { UGCClient } from 'ugcinc' ;
const client = new UGCClient ({ apiKey: 'YOUR_API_KEY' });
// Upload file directly to blob storage
const blob = await upload ( file . name , file , {
access: 'public' ,
handleUploadUrl: client . media . getUploadHandlerUrl ()
});
// Create media record from the uploaded blob
const media = await client . media . create ({
urls: [ blob . url ],
tag: 'uploads'
});
Request Body
The filename for the upload. This will be used as part of the storage path.
Optional MIME type of the file (e.g., image/jpeg, video/mp4). If not provided, defaults to allowing images, videos, and audio.
Response
Upload credentials The Vercel Blob client token for direct upload
The storage path where the file will be uploaded
import { upload } from '@vercel/blob/client' ;
import { UGCClient } from 'ugcinc' ;
const client = new UGCClient ({
apiKey: 'YOUR_API_KEY'
});
async function uploadFile ( file : File , tag ?: string ) {
// Step 1: Upload to blob storage
const blob = await upload ( file . name , file , {
access: 'public' ,
handleUploadUrl: client . media . getUploadHandlerUrl ()
});
// Step 2: Create media record
const response = await client . media . create ({
urls: [ blob . url ],
tag
});
if ( response . ok ) {
return response . data . data [ 0 ]; // Return the created media
}
throw new Error ( 'Failed to create media record' );
}
// Usage
const file = document . querySelector ( 'input[type="file"]' ). files [ 0 ];
const media = await uploadFile ( file , 'user-uploads' );
console . log ( 'Uploaded:' , media . url );
Vercel Blob Protocol Response
{
"type" : "blob.generate-client-token" ,
"clientToken" : "vercel_blob_client_..." ,
"url" : "https://blob.vercel-storage.com/..."
}