我正在使用 NodeJS 将 mp4s 的目录一一上传到 Azure。出于某种原因,视频索引在大约 20% 的时间内停止。我不清楚为什么。API 调用没有显示错误。尝试为视频加载数据时,我只得到“处理中”状态,但它永远不会结束。我必须手动删除视频并重新开始。
登录 videoindexer.ai 网站,我可以看到进程无限期停止:
这是我用于上传 MP4 的 NodeJS。如果我在这里做错了什么,我将不胜感激任何建议:
const fs = require('fs');
const path = require('path');
const fetch = require('node-fetch');
const FormData = require('form-data');
const uploadVideo = async (filePath) => {
const fileName = path.parse(filePath).name;
const url = `https://api.videoindexer.ai/${LOCATION}/Accounts/${ACCOUNTID}/Videos?accessToken=${TOKEN}&name=${fileName}&description=TEST&privacy=private&partition=some_partition`;
const fileBase = path.parse(filePath).base; // e.g. "video1.mp4"
const formData = new FormData();
formData.append('file', fs.createReadStream(filePath), { filename: fileBase });
const headers = {
'x-ms-client-request-id': '',
'Ocp-Apim-Subscription-Key': APIKEY,
...formData.getHeaders()
};
const response = await fetch(url, {
cache: 'no-cache',
headers,
method: 'POST',
body: formData
});
const json = await response.json();
if (json.ErrorType && json.Message) {
throw new Error(`${json.ErrorType} - ${json.Message}`);
}
console.log('Successfully uploaded video');
console.log(json);
return json.id;
};
uploadVideo('./video1.mp4').then((videoId) => console.log('result: ' + videoId)) // <- returns the correct videoId even when process stalls