0
我使用下面的代码使用Amazon Cognito注册用户。然后,我想在用户注册时将文件上传到Amazon S3 Bucket。使用Amazon Cognito上传到Amazon S3登录
一旦用户注册,我需要做些什么来配置桶准备上传? 谢谢
var roleArn = 'arn:aws:iam::123456:role/Cognito_Auth_Role';
var bucketName = 'MY_BUCKET';
AWS.config.region = 'eu-west-1';
var poolData = {
UserPoolId : 'POOL_ID', // your user pool id here
ClientId : 'CLIENT_ID' // your app client id here
};
var userPool = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserPool(poolData);
var userData = {
Username : 'username', // your username here
Pool : userPool
};
var attributeList = [];
var password
//Create Bucket
var bucket = new AWS.S3({
params: {
Bucket: bucketName
}
});
var dataEmail = {
Name : 'email',
Value : '[email protected]' // your email here
};
var dataPhoneNumber = {
Name : 'phone_number',
Value : '+1234567890' // your phone number here with +country code and no delimiters in front
};
...
var attributeEmail = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserAttribute(dataEmail);
var attributePhoneNumber = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserAttribute(dataPhoneNumber);
attributeList.push(attributeEmail);
attributeList.push(attributePhoneNumber);
var cognitoUser;
userPool.signUp('username', 'password', attributeList, null, function(err, result){
if (err) {
alert(err);
return;
}
cognitoUser = result.user;
console.log('user name is ' + cognitoUser.getUsername());
});
你好。我收到来自Chrome控制台的此错误:未捕获的错误:无法读取属性'刷新'null –
感谢百万人,拯救了我的一天!试图使用cognito将图像上传到S3时感到非常沮丧,然后遇到了您的代码......谢谢。 –
我说得太快了!事实证明,它使用Unauthenticated身份登录,只要我禁用,我得到一个NotAuthorizedException异常! –