You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无法通过Dailymotion API自动上传并发布视频求助

解决Dailymotion API上传视频卡在processing状态的问题

问题核心

通过API上传的视频始终处于processing状态,encoding_progress一直为0,无法发布显示;但手动上传完全正常,且使用相同Token能查询到手动上传的视频。

可能的原因及修复方案

1. 单步上传的误用

你参考的文档中单步上传示例是针对远程视频URL,而非本地文件直接上传。直接向/me/videos提交本地文件FormData,虽然会返回视频ID,但Dailymotion后台无法正确触发文件编码流程。

正确的本地文件上传必须遵循两步流程:

  • 先获取临时上传URL
  • 将文件上传至该临时URL
  • 再用返回的文件URL完成视频发布

2. 两步上传代码的优化调整

你之前的两步上传代码存在几个影响稳定性的问题,以下是修改后的版本:

app.post('/api/dailymotion/upload', async (req, res) => {
    const localVideoDirectory = path.join(__dirname, 'videos');

    try {
        const videos = fs.readdirSync(localVideoDirectory)
            .filter(file => file.endsWith('.mp4') || file.endsWith('.mkv') || file.endsWith('.avi'))
            .map(file => ({
                name: file,
                path: path.join(localVideoDirectory, file)
            }));

        if (!videos.length) {
            return res.status(400).send('No video files found in the local directory.');
        }

        console.log('[📂] Found Local Videos:', videos);
        const token = await getAccessToken();

        const uploadResults = await Promise.all(videos.map(async (video) => {
            try {
                console.log(`[📂] Preparing upload for: ${video.name}`);

                // Step 1: 获取临时上传URL
                const uploadUrlResponse = await axios.get(`${DAILY_API_BASE}/file/upload`, {
                    params: { access_token: token },
                });
                const uploadUrl = uploadUrlResponse.data.upload_url;
                console.log('[🌐] Upload URL:', uploadUrl);

                // Step 2: 用流上传文件到临时URL(避免大文件内存溢出)
                const form = new FormData();
                form.append('file', fs.createReadStream(video.path), {
                    filename: video.name,
                    contentType: 'video/mp4' // 根据实际文件类型指定正确ContentType
                });

                const uploadResponse = await axios.post(uploadUrl, form, {
                    headers: { ...form.getHeaders() },
                    maxContentLength: Infinity,
                    maxBodyLength: Infinity,
                    // 可选:添加上传进度监听
                    onUploadProgress: (progressEvent) => {
                        const percent = Math.round((progressEvent.loaded * 100) / progressEvent.total);
                        console.log(`[📈] Upload progress: ${percent}%`);
                    }
                });

                if (!uploadResponse.data?.url) {
                    throw new Error('Invalid upload response - missing file URL');
                }
                console.log('[✅] File uploaded to temporary storage:', uploadResponse.data.url);

                // Step 3: 发布视频(用表单编码提交参数)
                const publishResponse = await axios.post(
                    `${DAILY_API_BASE}/me/videos`,
                    new URLSearchParams({
                        url: uploadResponse.data.url,
                        title: video.name,
                        channel: 'music',
                        published: 'true',
                        is_created_for_kids: 'false',
                        privacy: 'public'
                    }),
                    {
                        headers: {
                            Authorization: `Bearer ${token}`,
                            'Content-Type': 'application/x-www-form-urlencoded'
                        },
                    }
                );

                console.log('[📤] Video published successfully:', publishResponse.data);
                return publishResponse.data;
            } catch (error) {
                console.error(`[❌] Error uploading ${video.name}:`, error.response?.data || error.message);
                return { error: error.response?.data || error.message, video: video.name };
            }
        }));

        res.json(uploadResults);
    } catch (error) {
        console.error('[❌] Upload endpoint error:', error.message);
        res.status(500).send('Error uploading videos.');
    }
});

3. 检查API Token权限

确认你的AccessToken包含以下必要权限:

  • video.create
  • video.upload
  • video.publish

可以通过以下命令验证权限:

curl -X GET -H "Authorization: Bearer <AUTH_TOKEN>" https://api.dailymotion.com/me?fields=permissions

4. 视频文件格式验证

虽然手动上传正常,但API对文件元数据的校验更严格,确保视频符合Dailymotion要求:

  • 编码标准:H.264视频编码 + AAC音频编码
  • 文件格式:优先使用.mp4格式
  • 文件大小:不超过平台限制(通常为2GB)

验证步骤

  1. 运行修改后的两步上传代码,观察上传进度和返回结果
  2. 上传完成后间隔30秒查询视频状态:
curl -X GET -H "Authorization: Bearer <AUTH_TOKEN>" https://api.dailymotion.com/video/<VIDEO_ID>?fields=id,status,encoding_progress,published
  1. 如果状态仍无变化,登录Dailymotion开发者后台查看错误日志,获取文件处理失败的具体原因

内容的提问来源于stack exchange,提问作者char

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 19:50:58