在Firebase Cloud Functions中的/tmp内创建子目录是否需要fs.mkdir()? [英] Is fs.mkdir() required to create a sub directory within /tmp in Firebase Cloud Functions?

查看:59
本文介绍了在Firebase Cloud Functions中的/tmp内创建子目录是否需要fs.mkdir()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们看下面的代码.如果我想将文件保存到/tmp/new_folder,我是否应该使用节点的fs.mkdir()函数,或者即使子目录尚不存在,也可以将其作为字符串提供给路径吗?

Let's look at the code below. If I wanted to save a file to /tmp/new_folder should I use node's fs.mkdir() function or can I just give it the path as a string even though the sub-directory does not exist yet?

还需要在连接字符串上使用path.join()来创建目标路径吗?

Also, is it a requirement to use path.join() over concatenating strings to create a the destination path?

// Download file from bucket.
const bucket = gcs.bucket(fileBucket);
const tempFilePath = path.join(os.tmpdir(), fileName);
const metadata = {
  contentType: contentType,
};
return bucket.file(filePath).download({
  destination: tempFilePath,
})

推荐答案

在Cloud Functions运行时中,/tmp已经存在,因此在此处写入文件之前无需尝试创建它.如果要在/tmp下创建一个子目录,则必须自行创建该子目录(并在完成功能后将其删除).

In the Cloud Functions runtime, /tmp already exists, so there is no need to try to create it before you write a file there. If you want to create a subdirectory under /tmp, you will have to create that on your own (and delete it when your function is done).

这篇关于在Firebase Cloud Functions中的/tmp内创建子目录是否需要fs.mkdir()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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