简体   繁体   English

如何从Google Cloud中的/ tmp文件夹访问文件?

[英]How to access files from /tmp folder in google cloud?

I followed the guide here: http://gunargessner.com/gcloud-env-vars/ 我在这里遵循了指南: http : //gunargessner.com/gcloud-env-vars/

After reading the comment http://gunargessner.com/gcloud-env-vars/#comment-4061927247 , I also placed the .env file in /tmp . 在阅读评论http://gunargessner.com/gcloud-env-vars/#comment-4061927247之后 ,我还将.env文件放置在/tmp

I would like to know how to set the contents of file /tmp/.env to environment so that my app can access it from process.env.<varname> 我想知道如何将文件/tmp/.env的内容设置为环境,以便我的应用程序可以从process.env.<varname>访问它process.env.<varname>

const { Storage } = require('@google-cloud/storage')
const storage = new Storage()
const bucketName = 'env-var'
await storage
  .bucket(bucketName)
  .file('.env')
  .download({ destination: '/tmp/.env' })
  .then(() => {
    console.log('env downloaded')
    afterEnvProcess()
  })

How do I now set the .env file to dotenv ? 现在如何将.env文件设置为dotenv

Well it depends on your app language but you can search for a dotenv lib on github. 好吧,这取决于您的应用程序语言,但是您可以在github上搜索dotenv库。

For example: 例如:

So when the app is started, you retrieve the .env file from the fileStorage service (ie Google Cloud Storage) to /tmp (for AppEngine case). 因此,在启动应用程序时,您将从fileStorage服务(即Google Cloud Storage)中的.env文件检索到/tmp (对于AppEngine而言)。 Then you can use the dotenv lib to parse the .env file en set the env vars. 然后,您可以使用dotenv库来解析.env文件,并设置env变量。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何访问 Google Cloud 中的 Laravel 文件夹 - How to access Laravel Folder in Google Cloud Appengine上的Node.js,google-cloud / storage:如何检查文件夹是否存在,如果存在,请从中获取所有文件? - Nodejs on Appengine, google-cloud/storage: How to check if a folder exists and if yes, get the all the files from it? 如何使用blobstore和Google云存储将文件上传到AppEngine中的自定义文件夹 - How to upload files to custom folder in AppEngine with blobstore and google cloud storage 如何访问从 Firebase 函数生成的 Google Cloud Build 日志文件 - How to access Google Cloud Build logs files generated from Firebase function Google云存储使用应用程序引擎创建存储区文件夹中所有文件的zip文件 - Google cloud storage create zip file with all files from a bucket folder with app engine 如何从开发环境访问Google Cloud Bucket - How to access Google Cloud Bucket from development Environment 如何从 C# 访问谷歌云存储桶 - How to access Google cloud storage bucket from c# 如何从Files API迁移到Google Cloud Storage? - How to migrate from The Files API to Google Cloud Storage? 如何在Google Cloud上从私有存储桶中提供图片/文件 - How to serve images/files from private bucket on Google Cloud Google Cloud App Engine-如何创建子域并将访问重定向到另一个文件/文件夹? - Google Cloud App Engine - How to create subdomains and redirect access to another file/folder?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM