gpt4 book ai didi

node.js - 如何将 google-auth-library 与带有 NodeJS 的 Google Cloud Storage 一起使用?

转载 作者:行者123 更新时间:2023-12-02 17:01:59 26 4
gpt4 key购买 nike

我想使用 Google Cloud Storage在 NodeJS 中,但使用 google-auth-library 进行身份验证具体来说:我想在 heroku 上托管它,所以我想将 secret 保存在环境变量中,而不是文件中(因为我必须提交文件才能部署到 heroku)。基本上 auth 库中的建议是什么: https://github.com/googleapis/google-auth-library-nodejs#loading-credentials-from-environment-variables

但我似乎无法将生成的客户端传递给 Storage 构造函数?

最佳答案

阅读代码[ 1 , 2 , 3 , 4 , 5 ] 您应该能够将凭据作为构造函数选项传递:

storageOptions = {
projectId: 'your-project-id',
credentials: {
client_email: 'your-client-email',
private_key: 'your-private-key'
}
};
client = new Storage(storageOptions);

关于node.js - 如何将 google-auth-library 与带有 NodeJS 的 Google Cloud Storage 一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53728105/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com