[英]Missing credentials in config while uploading image to AWS S3
Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1 Everytime I try to post images though postman toaws s3 I am getting this error.配置中缺少凭据,如果使用 AWS_CONFIG_FILE,请设置 AWS_SDK_LOAD_CONFIG=1 每次我尝试通过邮递员 toaws s3 发布图像时都会收到此错误。
require("./config/database").connect();
const express = require("express");
const jwt = require("jsonwebtoken");
const fileUpload = require("express-fileupload");
var bcrypt = require("bcryptjs");
const app = express();
app.use(fileUpload());
var AWS = require("aws-sdk");
app.post("/images", async (req, res) => {
AWS.config.update({
accessKeyId:process.env.AWS_ACCESS_KEY ,
secretAccesskey: process.env.AWS_SECRET_KEY,
region: process.env.AWS_BUCKET_REGION,
});
const s3 = new AWS.S3();
const fileContent = Buffer.from(req.files.data.data, "binary");
const params = {
Bucket:"newawspracticeimage",
Key: req.files.data.name,
Body: fileContent,
};
s3.upload(params, (err, data) => {
if (err) {
throw err;
}
res.send({
response_code: 200,
response_message: "Success",
response_data: data,
});
});
});```
Try to use one of the methods mentioned in the docs https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/setting-credentials-node.html尝试使用文档中提到的方法之一https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/setting-credentials-node.html
This one could be used for easiest approach https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/loading-node-credentials-json-file.html这可以用于最简单的方法https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/loading-node-credentials-json-file.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.