【问题标题】:Error: code: [CredentialsError]Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1错误:代码:[CredentialsError]缺少配置中的凭据,如果使用 AWS_CONFIG_FILE,请设置 AWS_SDK_LOAD_CONFIG=1
【发布时间】:2021-02-20 00:00:27
【问题描述】:

我正在使用 aws s3 上传图像,但我不断收到错误消息:如果使用 AWS_CONFIG_FILE,则在配置中缺少凭据,请设置 AWS_SDK_LOAD_CONFIG=1。有几个帖子谈到了同样的错误,但我无法解决它。 我正在使用带有所需私钥的 .env 环境文件。提前致谢。

代码如下:

const aws = require('aws-sdk');
const multer = require('multer');
const multerS3 = require('multer-s3');
const dotenv = require('dotenv');
dotenv.config();

const s3 = new aws.S3({});
aws.config.update({
    secretAccesKey: process.env.S3_ACCES_KEY,
    accessKeyId: process.env.S3_ACCES_KEY_SECRET,
    region: "eu-west-3",
});

const fileFilter = (req, file, cb)=>{
    if(file.mimetype === "image/jpeg" || file.mimetype === "image/png"){
        cb(null, true);
    }else{
        cb(new Error("Invalid file type, file must be JPG or PNG."), false);
    }
}
const upload = multer({
    fileFilter,
    storage: multerS3({
        acl: "public-read",
        s3: s3,
        bucket: "projectoene",
        acl: 'public-read',
        metadata: function(req,file, cb){
            cb(null, {fieldName: "Test"});
        },
        key: function(req,file,cb){
            cb(null, Date.now().toString());
        },
    }),
});
module.exports = upload;

【问题讨论】:

  • 问题可能是您输入了ACCES 而不是ACCESS
  • 不,我更改了它并重新加载它但没有工作

标签: node.js amazon-web-services amazon-s3


【解决方案1】:

我不得不更改我的存储桶策略和一些权限。之后效果很好

【讨论】:

    【解决方案2】:

    从后端将图像上传到 s3 时,我收到了相同的错误消息。我在没有使用 env 的情况下输入了实际的 aws 值,所以效果很好。

    【讨论】:

      猜你喜欢
      • 2020-11-28
      • 1970-01-01
      • 1970-01-01
      • 2020-10-07
      • 1970-01-01
      • 2022-01-12
      • 2020-12-04
      • 2019-02-24
      • 2017-08-31
      相关资源
      最近更新 更多