gpt4 book ai didi

amazon-web-services - 配置 : Cognito (for the unauthenticated) and S3 中缺少凭据

转载 作者:行者123 更新时间:2023-12-03 17:49:51 28 4
gpt4 key购买 nike

同时遵循简单的官方教程here(Uploading Photos to Amazon S3 from a Browser(using Cognito for unauthenticated users)) , 我收到错误 “配置中缺少凭据” .如下所示,代码很简单,但不知道为什么会出现错误,尽管我认为我完全遵循了教程的先决条件。我很好奇什么时候出现错误信息 “配置中缺少凭据”出现,以便我猜测原因。这是因为 AWS 发生了变化还是我做错了什么?
如果您让我知道正确的答案或任何提示,我将不胜感激。

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="https://sdk.amazonaws.com/js/aws-sdk-2.255.1.min.js"></script>
<script>
var bucketName = 'mama-swedenhouse-resources';
var bucketRegion = 'ap-northeast-2';
var identityPoolId = 'ap-northeast-2:f4250b2e-5d77-4413-bc3a-34c4xxxxxxxx'; //just hiding last 8 letters on this github issue

AWS.config.update({
region: bucketRegion,
credentials: new AWS.CognitoIdentityCredentials({
identityPoolId: identityPoolId
})
});

var s3 = new AWS.S3({
apiVersion: '2006-03-01',
params: {
Bucket: bucketName
}
});

function uploadPhoto() {

var files = document.getElementById('test-file-input').files;
if (!files.length) {
return alert('Please choose a file to upload first.');
}
var file = files[0];
var fileName = file.name;

s3.upload({
Key: fileName + ' ' + Math.floor(Date.now()),
Body: file,
ACL: 'public-read'
}, function (err, data) {
if (err) {
console.log(err);
return console.log('There was an error uploading your photo: ', err.message);
}
console.log('Successfully uploaded photo.');
});
};
</script>
</head>

<body>
<section>
<input type="file" name="test-file-input" id="test-file-input" accept="image/*">
<button id="uplaod-btn" onclick="uploadPhoto();">업로드</button>
</section>
</body>

</html>

错误消息(在 Chrome 的控制台上)
Error: Missing credentials in config
at constructor.fail (aws-sdk-2.255.1.min.js:50)
at constructor.validateStructure (aws-sdk-2.255.1.min.js:50)
at constructor.validateMember (aws-sdk-2.255.1.min.js:50)
at constructor.validate (aws-sdk-2.255.1.min.js:50)
at constructor.<anonymous> (aws-sdk-2.255.1.min.js:49)
at constructor.callListeners (aws-sdk-2.255.1.min.js:51)
at constructor.emit (aws-sdk-2.255.1.min.js:51)
at constructor.emitEvent (aws-sdk-2.255.1.min.js:50)
at constructor.e (aws-sdk-2.255.1.min.js:50)
at a.runTo (aws-sdk-2.255.1.min.js:52)
aws-s3-upload.html:48 There was an error uploading your photo: Missing credentials in config

最佳答案

得到它的工作设置凭据是这样的:

AWS.config.region = 'REGION';
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: 'IDENTITY_POOL_ID',
});

希望这可以帮助!

关于amazon-web-services - 配置 : Cognito (for the unauthenticated) and S3 中缺少凭据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50880329/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com