본문으로 건너뛰기

비디오 업로드

cb.video.upload(file, options) 는 청크 업로드(init → chunk × N → complete)를 SDK 내부에서 자동으로 처리합니다. 별도로 청크를 직접 다룰 필요가 없습니다.

💡 업로드는 앱 멤버 JWT 가 필요합니다 — cb.auth.signInMember(...) 또는 소셜 로그인으로 먼저 로그인하세요.

기본 업로드

typescript
const fileInput = document.getElementById('video-input') as HTMLInputElement
const file = fileInput.files?.[0]
if (!file) throw new Error('파일을 선택해주세요')

const video = await cb.video.upload(file, {
    title: '동영상 제목',
    description: '동영상 설명',
    visibility: 'public',         // 'public' | 'unlisted' | 'private'
    tags: ['vlog', 'travel']
})

console.log('업로드 완료:', video.id)
console.log('초기 상태:', video.status)  // 보통 'processing'

진행률 표시

upload()onProgress 콜백이 청크 단위로 호출됩니다.

typescript
const video = await cb.video.upload(file, {
    title: '동영상 제목',
    visibility: 'public',
    onProgress: (progress) => {
        console.log(`${progress.phase}: ${progress.percentage}%`)
        // phase: 'uploading' | 'finalizing'
        // percentage: 0~100
        // currentSpeed: bytes/sec
    }
})

트랜스코딩 완료 대기

업로드 직후 비디오 상태는 processing 입니다. 트랜스코딩이 끝나야 ready 가 되어 재생 가능합니다.

typescript
const video = await cb.video.upload(file, { title: '...', visibility: 'public' })

// 트랜스코딩 완료까지 polling 대기 — SDK 기본값: timeout 30분, interval 5초
const ready = await cb.video.waitForReady(video.id)
// 또는 명시적으로 override
// const ready = await cb.video.waitForReady(video.id, { timeout: 30 * 60 * 1000, interval: 5000 })
console.log('재생 가능:', ready.status)  // 'ready'

트랜스코딩 상태 직접 조회

waitForReady 로 끝까지 기다리는 대신, 진행 상태를 직접 조회하거나 실패 시 재시도할 수 있습니다.

typescript
// 현재 트랜스코딩 상태 조회
const status = await cb.video.getTranscodeStatus('video-id')
console.log(status)  // { status: 'processing' | 'ready' | 'failed', ... }

// 실패한 트랜스코딩 재시도
if (status.status === 'failed') {
    await cb.video.retryTranscode('video-id')
}

💡 단순히 "재생 가능할 때까지 기다리기"만 필요하면 위 cb.video.waitForReady(videoId) 가 더 간단합니다.

다중 스토리지로 업로드

typescript
const video = await cb.video.storage.upload(storageId, file, {
    title: '동영상 제목',
    visibility: 'public'
})