我使用ng-file-upload來將照片上傳到S3錯誤。我測試了我的S3存儲和我與NG-文件上傳demo tool政策/簽名生成器,並已成功地用它來上傳照片到我的水桶。經由NG-文件上傳上傳到Amazon S3; 400
編輯:一個關鍵的區別似乎是增加了一個頭的:
Authorization:Token 3j4fl8jk0lqfkj4izj2w3ljfopljlwep1010notreal
存在於我的代碼,但不是在演示頁。也許這是我的角度應用程序。
通過涼亭裝,拿着相關組件,嘗試上傳的文件,並得到看起來像這樣的錯誤:
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 [some-code-here]
。在AWS documentation
來看,InvalidArgument
是有人相當新的AWS有點不透明。
這裏是我在編碼策略(蟒蛇):
#exptime = '2100-07-31T06:23:35Z' #for debugging
policy_document = {"expiration": exptime,
"conditions": [
{"bucket": settings.AWS_STORAGE_BUCKET_NAME},
["starts-with", '$key', ""],
{"acl": "private"},
["starts-with", "$Content-Type", ""],
["starts-with", "$filename", ""],
["content-length-range", 0, 5000000]
]
}
要重申,這一政策與上述演示工作,所以我想到一個問題,在我的前端實現:
$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
});
}
3小時後,這個答案做的工作! –