我很抱歉。我以前提出了同样的问题,但它被认为是与这个答案重复的。我真的不明白答案,我也不明白为什么这个问题会回答我的问题。对我来说很不一样。我需要得到图像对象,但答案是创建一个流。有人能帮我把这个问题的答案和我的问题联系起来吗?我是新来的云功能。请
=======================================================================
如果我使用云函数作为Firebase云存储触发器。我可以得到像这样的图像对象
exports.compressImage = functions.region("asia-east2").storage.object().onFinalize(async (object) => {
// I can get the `object` easily in here
})但是现在我想要使用防火墙触发器来做一些事情,并且我想从我的存储触发器中的桶中获取一个对象。
exports.dbEventsOnCreate = functions..firestore.document(path).onCreate(async (snapshot,context) => {
// I want to get an image `object` with a specific path from firebase storage bucket in here
})这是我在火场存储中的图像路径
gs://xxx.appspot.com/eventPoster/{uid}/{imageID}

那么,如何从路径中的桶中获取图像对象,就像我的云函数防火墙触发器中的那样?
发布于 2020-07-01 00:08:23
要处理云函数上的文件,您可以遵循本指南,只需几句话就可以找到更详细的信息
要下载文件:
// Download file from bucket.
const bucket = admin.storage().bucket(fileBucket);
const tempFilePath = path.join(os.tmpdir(), fileName);
const metadata = {
contentType: contentType,
};
await bucket.file(filePath).download({destination: tempFilePath});
console.log('Image downloaded locally to', tempFilePath);这将将图像保存到一个临时文件夹中,因为这是在文档上重新生成的内容。
使用gcs.bucket.file(filePath).download将文件下载到Cloud实例的临时目录中。在此位置,您可以根据需要处理文件。
若要上载该文件:
await bucket.upload(tempFilePath, {
destination: thumbFilePath,
metadata: metadata,
});
// Once the thumbnail has been uploaded delete the local file to free up disk space.
return fs.unlinkSync(tempFilePath);https://stackoverflow.com/questions/62655219
复制相似问题