我的毕业项目是将视频转换成文本,我试图读取上传在Firebase存储&从android应用程序发送的视频,将其发送到TenserFlow模型,但我无法读取视频。
exports.readVideo = functions.storage
.object()
.onFinalize(async (object) => {
const bucket = admin.storage().bucket(object.bucket);
const tempFilePath = path.join(os.tmpdir(), object.name);
console.log(tempFilePath);
console.log('download');
// note download
await bucket
.file(object.name!)
.download({
destination: tempFilePath,
})
.then()
.catch((err) => {
console.log({
type: 'download',
err: err,
});
});
console.log('read');
// note read
let stream = await bucket
.file(object.name!)
.createReadStream({
start: 10000,
end: 20000,
})
.on('error', function (err) {
console.log('error 1');
console.log({ error: err });
})
await new Promise((resolve, reject) => {
console.log('error 2');
stream.on('finish', resolve);
console.log('error 3');
stream.on('error', reject);
console.log("end!")
stream.on('end', resolve);
}).catch((error) => {
// successMessage is whatever we passed in the resolve(...) function above.
// It doesn't have to be a string, but if it is only a succeed message, it probably will be.
console.log("oups! " + error)
});
console.log('tempFile size2', fs.statSync(tempFilePath).size);
return fs.unlinkSync(tempFilePath);
});
我得到了这个错误:
函数执行耗时60008毫秒,完成状态:'超时'。
如错误信息所示,云功能的常规文件系统是只读的。唯一可以写入的地方是 /tmp
的文件中也有显示。云功能中的文件系统访问. 我不知道为什么 os.tmpdir()
并没有给你提供这个路径的位置,但你可能想把这个目录硬编码。
有一件事要记住。/tmp
是一个内存磁盘而不是物理磁盘 所以你分配的内存需要有足够的空间来存放你写到它上面的文件。