User Assets

POSThttps://sangtao.ai/api/v2/user-assets/presign

Tài liệu cho User Assets.

Upload và quản lý media assets (video, hình ảnh, âm thanh). Assets dùng làm intro/outro, logo, watermark, nhạc nền, voiceover, thumbnail trong tạo video.

Luồng Upload

text
1. POST /user-assets/presign  →  get sasUrl + blobPath
2. PUT  sasUrl (binary)       →  upload file to blob
3. POST /user-assets/confirm  →  register asset in DB
Note: Presign response có category, maxSizeBytes, allowedContentTypes — dùng để validate phía client trước khi upload.

Bước 1: Presign

POST /api/v2/user-assets/presign

FieldTypeDescription
fileName*stringTên file gốc (ví dụ "logo.png")
contentType*stringMIME type (ví dụ "image/png", "video/mp4")
bash
curl -X POST https://sangtao.ai/api/v2/user-assets/presign \\
  -H "X-Api-Key: YOUR_API_KEY" \\
  -H "Content-Type: application/json" \\
  -d '{"fileName": "my-logo.png", "contentType": "image/png"}'
json
{
  "success": true,
  "data": {
    "sasUrl": "https://blob.sangtao.ai/...?sv=...&sig=...",
    "blobPath": "d15ed.../user-assets/1e65...png",
    "publicUrl": "https://blob.sangtao.ai/user-assets/...",
    "expiresAt": "2026-06-08T12:30:00Z",
    "category": "image",
    "maxSizeBytes": 52428800,
    "allowedContentTypes": ["image/png", "image/jpeg", "image/webp", "image/svg+xml"]
  }
}

Bước 2: Upload lên Blob

PUT file binary trực tiếp lên sasUrl với header x-ms-blob-type: BlockBlob.

bash
curl -X PUT "PRESIGNED_SAS_URL" \\
  -H "x-ms-blob-type: BlockBlob" \\
  -H "Content-Type: image/png" \\
  --data-binary @my-logo.png

Bước 3: Xác nhận

POST /api/v2/user-assets/confirm

FieldTypeDescription
blobPath*stringBlob path trả về từ presign
fileName*stringTên file gốc
contentType*stringMIME type
fileSizeBytes*numberKích thước file (bytes)
purposestringMục đích asset (optional — xem bảng bên dưới)
labelstringNhãn hiển thị
durationSecnumberThời lượng giây (video/audio)
aspectRatiostringTỷ lệ khung (ví dụ "16:9")
bash
curl -X POST https://sangtao.ai/api/v2/user-assets/confirm \\
  -H "X-Api-Key: YOUR_API_KEY" \\
  -H "Content-Type: application/json" \\
  -d '{
    "blobPath": "d15ed.../user-assets/1e65...png",
    "fileName": "my-logo.png",
    "contentType": "image/png",
    "fileSizeBytes": 245000,
    "purpose": "logo"
  }'

Danh sách Assets

GET /api/v2/user-assets

FieldTypeDescription
categorystringLọc theo category: video, image, audio, document
purposestringLọc theo purpose (xem bảng purpose)
bash
curl "https://sangtao.ai/api/v2/user-assets?purpose=logo" \\
  -H "X-Api-Key: YOUR_API_KEY"
json
{
  "success": true,
  "data": [
    {
      "id": 42,
      "url": "https://blob.sangtao.ai/user-assets/abc123/my-logo.png",
      "fileName": "my-logo.png",
      "mimeType": "image/png",
      "fileSizeBytes": 245000,
      "category": "image",
      "purpose": "logo",
      "label": "My Brand Logo",
      "thumbnailUrl": null,
      "durationSec": null,
      "aspectRatio": null,
      "hasAudio": false,
      "createdAt": "2026-06-08T10:30:00Z"
    }
  ]
}

Các field response

FieldTypeDescription
id*numberID của asset
url*stringURL công khai của asset
fileName*stringTên file gốc
mimeType*stringMIME type (ví dụ "video/mp4")
fileSizeBytes*numberKích thước (bytes)
category*stringTự phát hiện: video, image, audio, document
purpose*stringMục đích asset
labelstringNhãn hiển thị (nullable)
thumbnailUrlstringURL thumbnail (nullable)
durationSecnumberThời lượng (video/audio)
aspectRatiostringTỷ lệ khung
hasAudiobooleanFile có audio track không (video/audio)
createdAtstringThời điểm tạo (ISO 8601)

Lấy Asset theo ID

GET /api/v2/user-assets/{id}

bash
curl https://sangtao.ai/api/v2/user-assets/42 \\
  -H "X-Api-Key: YOUR_API_KEY"

Cập nhật Asset

PUT /api/v2/user-assets/{id}

FieldTypeDescription
labelstringNhãn mới
purposestringMục đích mới
bash
curl -X PUT https://sangtao.ai/api/v2/user-assets/42 \\
  -H "X-Api-Key: YOUR_API_KEY" \\
  -H "Content-Type: application/json" \\
  -d '{"label": "New Label", "purpose": "watermark"}'

Xóa Asset

DELETE /api/v2/user-assets/{id}

bash
curl -X DELETE https://sangtao.ai/api/v2/user-assets/42 \\
  -H "X-Api-Key: YOUR_API_KEY"

Xóa nhiều

POST /api/v2/user-assets/bulk-delete

bash
curl -X POST https://sangtao.ai/api/v2/user-assets/bulk-delete \\
  -H "X-Api-Key: YOUR_API_KEY" \\
  -H "Content-Type: application/json" \\
  -d '{"ids": [42, 43, 44]}'

Dung lượng sử dụng

GET /api/v2/user-assets/usage

bash
curl https://sangtao.ai/api/v2/user-assets/usage \\
  -H "X-Api-Key: YOUR_API_KEY"
json
{
  "success": true,
  "data": {
    "video":    { "count": 3, "maxCount": 20, "storageBytes": 150000000, "maxStorageBytes": 2147483648 },
    "image":    { "count": 12, "maxCount": 100, "storageBytes": 8500000, "maxStorageBytes": 524288000 },
    "audio":    { "count": 2, "maxCount": 30, "storageBytes": 25000000, "maxStorageBytes": 524288000 },
    "document": { "count": 0, "maxCount": 20, "storageBytes": 0, "maxStorageBytes": 209715200 }
  }
}

Giá trị Purpose

PurposeDùng cho
outro_videoGhép cuối video khi render
intro_videoGhép đầu video khi render
logoOverlay logo lên video khi render
watermarkWatermark overlay trong render pipeline
background_musicNhạc nền tùy chỉnh cho tất cả loại video
voiceoverFile giọng nói do user upload (thay TTS)
thumbnailThumbnail tùy chỉnh cho job đã publish
generalFile tham khảo chung

Giới hạn theo Category

CategoryContent TypesTối đaSố lượng
videovideo/mp4, video/webm500 MB20
imageimage/png, jpeg, webp, svg+xml50 MB100
audioaudio/mpeg, wav, ogg, aac100 MB30
documentapplication/pdf, text/csv, application/json200 MB20

Mã lỗi

MãKhi nào
400Content type không hợp lệ hoặc thiếu trường bắt buộc
401Chưa xác thực
404Asset không tồn tại hoặc không thuộc user
409Conflict — blobPath đã được confirm
429Đã đạt giới hạn số lượng hoặc dung lượng