尽管我可以使用访问密钥和秘密密钥将文件上传到S3存储桶。
AND
我正在尝试上传一个文件到AWS S3存储桶,但不使用访问密钥和秘密密钥。请协助我。
这是我的代码:
import {path} from "path";
const fs = require('fs');
const AWS = require('aws-sdk');
AWS.config.update({region: 'Region'});
// Enter copied or downloaded access ID and secret key here
const ID = 'id';
const SECRET = 'id';
// The name of the bucket that you have created
const BUCKET_NAME = 'name';
const s3 = new AWS.S3({
accessKeyId: ID,
secretAccessKey: SECRET
});
const FILE_PATH = 'filepath';
const uploadFile = (fileName) => {
// Read content from the file
const fileContent = fs.readFileSync(fileName);
// Setting up S3 upload parameters
const params = {
Bucket: BUCKET_NAME,
Key: path.basename(FILE_PATH), // File name you want to save as in S3
Body: fileContent
};
// Uploading files to the bucket
s3.upload(params, function(err, data) {
if (err) {
throw err;
}
console.log('File uploaded successfully. ${data.Location}');
});
};
uploadFile(FILE_PATH);