Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 错误:代码:[CredentialsError]配置中缺少凭据,如果使用AWS\u配置文件,请将AWS\u SDK\u加载\u配置设置为1_Node.js_Amazon Web Services_Amazon S3 - Fatal编程技术网

Node.js 错误:代码:[CredentialsError]配置中缺少凭据,如果使用AWS\u配置文件,请将AWS\u SDK\u加载\u配置设置为1

Node.js 错误:代码:[CredentialsError]配置中缺少凭据,如果使用AWS\u配置文件,请将AWS\u SDK\u加载\u配置设置为1,node.js,amazon-web-services,amazon-s3,Node.js,Amazon Web Services,Amazon S3,我正在使用aws s3上载图像,但我一直遇到错误:配置中缺少凭据,如果使用aws\u config\u文件,请将aws\u SDK\u LOAD\u config=1。有好几篇帖子都在谈论同一个错误,但我无法解决它。 我正在使用带有所需私钥的.env环境文件。提前谢谢 代码如下: const aws = require('aws-sdk'); const multer = require('multer'); const multerS3 = require('multer-s3'); cons

我正在使用aws s3上载图像,但我一直遇到错误:配置中缺少凭据,如果使用aws\u config\u文件,请将aws\u SDK\u LOAD\u 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;

我必须更改我的桶策略cors和一些权限。在那之后工作得很好

我从后端将图像上载到s3时收到了相同的错误消息。我在没有使用env的情况下输入了实际的aws值,因此它工作得很好。

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