Amazon s3 直接s3 boto3文件上载:访问被拒绝
我正试图通过flask服务器使用react本机应用程序直接将视频上传到s3。我从heroku那里了解到了这一点 自然反应Amazon s3 直接s3 boto3文件上载:访问被拒绝,amazon-s3,flask,boto3,Amazon S3,Flask,Boto3,我正试图通过flask服务器使用react本机应用程序直接将视频上传到s3。我从heroku那里了解到了这一点 自然反应 postVideo({className, path}) { console.log(`posting ${className} video at ${path}`); const vidName = path.substring(path.indexOf('/video_')+1); return fetch(SERVER+'/sign_s3?file_nam
postVideo({className, path}) {
console.log(`posting ${className} video at ${path}`);
const vidName = path.substring(path.indexOf('/video_')+1);
return fetch(SERVER+'/sign_s3?file_name='+vidName+'&file_type=video/mp4', {
method: 'GET',
})
.then((response) => {
response.json().then((responseText)=> {
this.uploadVideo({ uri: path, name: vidName, type: 'video/mp4' }, responseText.data, responseText.url);
})
})
.catch((error) => {
console.error(error);
});
}
uploadVideo(file, s3Data, url) {
let form = new FormData();
for(key in s3Data.fields) {
form.append(key, s3Data.fields[key]);
}
console.log(s3Data);
form.append('file', file);
return fetch(url, {
method: 'PUT',
body: form,
})
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});
}
Flask服务器(环境变量存储在.env
文件中并加载)
我设置了一个可以完全访问s3的用户(它也不能使用根凭据)
用户策略(对s3的完全访问)
CORS已按此方式设置
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<AllowedMethod>DELETE</AllowedMethod>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>
如果我将bucket设置为可公开访问,则上传会起作用,这让我觉得签名过程一定有问题(因为我也确定我给了用户足够的权限来访问bucket?我最近也遇到了这个问题。对我来说,将两个acl设置从“公共读取”更改为“私有”后,它就起作用了 我想安装有问题。是否确实传递了正确的访问权限和密钥?您可以使用测试凭据以排除这些凭据。评论迟了,但是你能分享一些关于这个问题的信息吗?
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "s3:*",
"Resource": "*"
}
]
}
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<AllowedMethod>DELETE</AllowedMethod>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>
<Error>
<Code>
AccessDenied
</Code>
<Message>
Access Denied
</Message>
<RequestId>
3399C78F3BD59FAF
</RequestId>
<HostId>
mTgI5xc/iz1z69NRanZ3VfAizg6PPf0s2AdC3nE1nMqDfJYlo2trMMRUmCZMusY1hJ0xBIW21Aw=
</HostId>
</Error>