清理临时目录Firebase云功能 [英] Cleanup Temp Directory Firebase cloud Functions
本文介绍了清理临时目录Firebase云功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在为我的Web应用程序使用Cloud Functions for Firebase.我需要为在Firebase Storage上上传的任何图像创建缩略图.为此,我需要将上传的文件从GCS存储桶下载到temp目录(使用mkdirp-promise
),并应用imageMagick
命令创建缩略图. ( Firebase函数示例-生成缩略图)
I am using Cloud Functions for Firebase for my webapp. I need to create thumbnail for any image uploaded on Firebase Storage. For that I need to download the uploaded file from GCS bucket to temp directory(using mkdirp-promise
), and apply imageMagick
command to create a thumbnail. (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云存储或Google云存储配额?
- 成功上传新创建的缩略图文件后,如何清理临时目录?这样我的配额就不会超过.
- where is this
temp
directory created? - Is this temp storage counted against my firebase cloud storage or Google cloud Storage quota?
- How can I cleanup my temp directory, after i have successfully uploaded newly created thumbnail file? So that my quota doesnt exceed.
推荐答案
- 临时目录在
tmpfs
中创建,该目录在Cloud Functions环境中保留在内存中.请参见 https://cloud.google.com/functions/pricing#local_disk - 由于
tmpfs
保留在内存中,因此它会计入函数的内存使用量. - 您可以通过调用
fs.rmdir()
来删除目录: https://nodereferrer> https://nodejs.org/api/fs.html#fs_fs_rmdir_path_callback
- The temp directory is created in
tmpfs
, which in the Cloud Functions environment is kept in memory. See https://cloud.google.com/functions/pricing#local_disk - Since
tmpfs
is kept in memory, it counts against the memory usage of your Functions. - You remove a directory by calling
fs.rmdir()
: https://nodejs.org/api/fs.html#fs_fs_rmdir_path_callback
这篇关于清理临时目录Firebase云功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文