我正在为我的webapp使用Cloud Functions for Firebase . 我需要为在Firebase存储上上传的任何图片创建缩略图 . 为此,我需要将上传的文件从GCS存储桶下载到临时目录(使用 mkdirp-promise
),然后应用 imageMagick
命令创建缩略图 . (Firebase Function Samples- Generate Thumbnail)
return mkdirp(tempLocalDir).then(() => {
console.log('Temporary directory has been created', tempLocalDir);
// Download file from bucket.
return bucket.file(filePath).download({
destination: tempLocalFile
});
}).then(() => {
//rest of the program
});
});
我的问题是:
-
这个
temp
目录在哪里创建? -
此临时存储是否计入我的Firebase Cloud 存储或Google Cloud 存储配额?
-
成功上传新创建的缩略图文件后,如何清理临时目录?所以我的配额不会超过 .
2 回答
临时目录在
tmpfs
中创建,在 Cloud 函数环境中保存在内存中 . 见https://cloud.google.com/functions/pricing#local_disk由于
tmpfs
保留在内存中,因此它会计算函数的内存使用量 .您通过调用
fs.rmdir()
删除目录:https://nodejs.org/api/fs.html#fs_fs_rmdir_path_callback以下是我为Google I / O中的“Fire!sale”持续部署演示编写的一些代码(警告:它是TypeScript,而不是JavaScript . 这让我可以使用更容易阅读的await / async,特别是在错误处理)
然后在我的Cloud Functions代码中,我可以执行以下操作: