清理临时目录Firebase云功能 [英] Cleanup Temp Directory Firebase cloud Functions

查看:68
本文介绍了清理临时目录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
  });
});

我的问题是:

  1. temp目录在哪里创建?
  2. 此临时存储是否计入我的Firebase云存储或Google云存储配额?
  3. 成功上传新创建的缩略图文件后,如何清理临时目录?这样我的配额就不会超过.
  1. where is this temp directory created?
  2. Is this temp storage counted against my firebase cloud storage or Google cloud Storage quota?
  3. How can I cleanup my temp directory, after i have successfully uploaded newly created thumbnail file? So that my quota doesnt exceed.

推荐答案

  1. 临时目录在tmpfs中创建,该目录在Cloud Functions环境中保留在内存中.请参见 https://cloud.google.com/functions/pricing#local_disk
  2. 由于tmpfs保留在内存中,因此它会计入函数的内存使用量.
  3. 您可以通过调用fs.rmdir()来删除目录: https://nodereferrer> https://nodejs.org/api/fs.html#fs_fs_rmdir_path_callback
  1. 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
  2. Since tmpfs is kept in memory, it counts against the memory usage of your Functions.
  3. You remove a directory by calling fs.rmdir(): https://nodejs.org/api/fs.html#fs_fs_rmdir_path_callback

这篇关于清理临时目录Firebase云功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆