javascript - 在 Firebase 存储中为文件创建 readStream
问题描述
Firebase 存储的读取流:
我的 Google firebase 存储中有文件,我想为其创建读取流(使用 javascript/node js)。(然后我打算将此读取流通过管道传输到某个中间件,然后是写入流,但这对于这个问题并不重要。)代码片段显示了我在做什么,但是当我将 readStream 打印到控制台时,我得到了一个 DestroyableTransform 对象而不是 ReadableStream。我觉得我的代码与文档非常相似。有谁知道可能出了什么问题?
const filePath = 'image.png';
const getReadStream = (filePath) => {
let file;
try {
file = admin
.storage()
.bucket()
.file(filePath);
} catch (err) {
console.log(err);
}
const readStream = file.createReadStream()
.on('error', (err) => {
throw err;
});
console.log(readStream);
return readStream;
};
解决方案
这是一个可能的答案。
const filePath = 'image.png';
const getReadStream = (filePath) => {
let file;
try {
file = admin
.storage()
.bucket(filePath);
} catch (err) {
console.log(err);
}
const readStream = file.createReadStream()
.on('error', (err) => {
throw err;
});
console.log(readStream);
return readStream;
};
您应该排除内部的“文件”句子。
推荐阅读
- java - 使用泛型在 Map 中存储和调用方法
- curl - 如何从控制器和操作名称中获取 URL(遵循 CUrlManager 的规则)?
- android - 为什么recycleview不滚动折叠appbarlayout
- java - 为什么每次调用 findById() 时日历字段会自动增加
- c# - 在模型 .net Core 2.2 中将数据类型从 int 更改为 long 的关键属性
- flutter - 如何在 Flutter 中限制文本输入中的特殊字符?
- php - 如何允许空字段或替代解决未定义的偏移空值?
- rally - 如何使用 rally Webservice API 创建新连接
- java - 流()和并行流()。为什么 API 开发人员采用两种方法?
- java - 如何在 Ldap 中将用户帐户控制属性修复为 512