[英]Process.env not reading? Amazon S3 Bucket
I'm trying to set my Amazon AWS access key and secret by using multer:我正在尝试使用 multer 设置我的 Amazon AWS 访问密钥和秘密:
var upload = multer({ secretAccessKey: process.env.AWS_ACCESS_SECRET, accessKeyId: process.env.AWS_ACCESS_KEY, })
In my zshrc file I've done在我的 zshrc 文件中,我已经完成了
export AWS_ACCESS_SECRET="mysecret" export AWS_ACCESS_KEY="mykey"
however on running node, I get the error但是在运行节点上,我得到了错误
if (.opts secretAccessKey) throw new Error('secretAccessKey is required')
However hardcoding the key and secret makes it work, but obviously that's not the safest way to go.然而,硬编码密钥和秘密使其工作,但显然这不是 go 最安全的方法。
I have done source ~/.zshrc but it still is showing the error.我已经完成了 source ~/.zshrc 但它仍然显示错误。
Multer out of the box doesn't support s3.开箱即用的 Multer 不支持 s3。 The way you're creating a new
multer
object is incorrect.您创建新
multer
object 的方式不正确。 The only available options when creating a new multer
object are dest/storage
, fileFilter
and limits
.创建新的
multer
object 时唯一可用的选项是dest/storage
、 fileFilter
和limits
。
If you want to use Multer with S3 directly, you can use multer-s3
.如果你想直接使用 Multer 和 S3,你可以使用
multer-s3
。 With that you can pass in a new option storage
that will take your secretAccessKey
and your accessKeyId
.有了它,您可以传入一个新的选项
storage
,它将获取您的secretAccessKey
和您的accessKeyId
。
If you don't use multer-s3
you can use multer
with aws-sdk
's S3
Client .如果您不使用
multer-s3
,您可以将multer
与aws-sdk
的S3
Client一起使用。
var multer = require('multer'); var AWS = require('aws-sdk'); var accessKeyId = process.env.AWS_ACCESS_KEY; var secretAccessKey = process.env.AWS_ACCESS_SECRET; var upload = multer({dest: '/temp'}); var s3 = new AWS.S3({ accessKeyId: accessKeyId, secretAccessKey: secretAccessKey });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.