Python 通过ng文件上传上传至Amazon S3;错误400
我正在使用将照片上载到S3。我已经用ng文件上传测试了我的S3 bucket和我的策略/签名生成器,并成功地使用它将照片上传到我的bucketPython 通过ng文件上传上传至Amazon S3;错误400,python,angularjs,amazon-web-services,file-upload,amazon-s3,Python,Angularjs,Amazon Web Services,File Upload,Amazon S3,我正在使用将照片上载到S3。我已经用ng文件上传测试了我的S3 bucket和我的策略/签名生成器,并成功地使用它将照片上传到我的bucket 编辑:一个关键的区别似乎是添加了一个标题: 授权:令牌3j4fl8jk0lqfkj4izj2w3ljfopljlwep1010notreal 这在我的代码中出现,但在演示页面中没有。也许是我的angular应用程序 通过bower安装,获取相关组件,尝试上载文件,并出现如下错误: 400: <?xml version="1.0" encodi
编辑:一个关键的区别似乎是添加了一个标题:
授权:令牌3j4fl8jk0lqfkj4izj2w3ljfopljlwep1010notreal
这在我的代码中出现,但在演示页面中没有。也许是我的angular应用程序
通过bower安装,获取相关组件,尝试上载文件,并出现如下错误:
400: <?xml version="1.0" encoding="UTF-8"?>
<Error>
<Code>InvalidArgument</Code>
<Message>Unsupported Authorization Type</Message>
<ArgumentName>Authorization</ArgumentName>
<ArgumentValue>Token 3j4fl8jk0lqfkj4izj2w3ljfopljlwep1010notreal</ArgumentValue>
<RequestId>F1F5FK-not-real-81FED9CA</RequestId>
<HostId>CQEW98p3D2e+pVz-not-real-codeu28m7asqpGjagL3409gj3f4kijKJpofk</HostId>
</Error>
在四处搜索时,我注意到了400多个错误,但使用ArgumentValue
作为Token[此处的一些代码]
的情况并不多
看看,InvalidArgument
对于AWS新手来说有点不透明
下面是我正在编码的策略(Python):
重申一下,上述演示的这一策略是有效的,因此我预计我的前端实现会出现问题:
$scope.upload = function(file) {
file.upload = Upload.upload({
url: 'https://mybucket.s3-us-west-2.amazonaws.com',
method: 'POST',
fields: {
key: file.name,
AWSAccessKeyId: myAccessKeyId,
acl: 'private',
policy: myPolicyEncoded,
signature: mySignatureEncoded,
"Content-Type": file.type === null ||
file.type === '' ? 'application/octet-stream' : file.type,
filename: file.name
},
file: file
});
}
我花了一段时间才找到它,但正如我的编辑所指出的,在查找请求头时,Angular应用程序的登录/身份验证过程中使用的令牌被作为默认令牌发送,而Amazon的服务不喜欢这样。删除此特定案例的http请求中的标头解决了此问题 因此,我的前端上传服务如下所示:
$scope.upload = function(file) {
file.upload = Upload.upload({
url: 'https://mybucket.s3-us-west-2.amazonaws.com',
method: 'POST',
fields: {
key: file.name,
AWSAccessKeyId: myAccessKeyId,
acl: 'private',
policy: myPolicyEncoded,
signature: mySignatureEncoded,
"Content-Type": file.type === null ||
file.type === '' ? 'application/octet-stream' : file.type,
filename: file.name
},
headers: {
'Authorization': undefined
},
file: file
});
}
这是一个旧线程,但我刚刚遇到了这个错误 您可以将自定义标头放入CORS策略中,而不是删除该标头,如:
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>Authorization</AllowedHeader>
</CORSRule>
</CORSConfiguration>
*
邮递
放
3000
授权
3小时后,这个答案成功了!
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>Authorization</AllowedHeader>
</CORSRule>
</CORSConfiguration>