[ PROMPT_NODE_24340 ]
Stream API 参考
[ SKILL_DOCUMENTATION ]
# Stream API 参考
上传、播放、实时流媒体及管理 API。
## 上传 API
### 创作者直接上传 (推荐)
**后端: 创建上传 URL (SDK)**
typescript
import Cloudflare from 'cloudflare';
const client = new Cloudflare({ apiToken: env.CF_API_TOKEN });
const uploadData = await client.stream.directUpload.create({
account_id: env.CF_ACCOUNT_ID,
maxDurationSeconds: 3600,
requireSignedURLs: true,
meta: { creator: 'user-123' }
});
// 返回: { uploadURL: string, uid: string }
**前端: 上传文件**
typescript
async function uploadVideo(file: File, uploadURL: string) {
const formData = new FormData();
formData.append('file', file);
return fetch(uploadURL, { method: 'POST', body: formData }).then(r => r.json());
}
### 从 URL 上传
typescript
const video = await client.stream.copy.create({
account_id: env.CF_ACCOUNT_ID,
url: 'https://example.com/video.mp4',
meta: { name: 'My Video' },
requireSignedURLs: false
});
## 播放 API
### 嵌入播放器 (iframe)
html
<iframe
src="https://customer-.cloudflarestream.com/