我有一個表格來上傳文件到我的AWS S3存儲桶,這是形式上傳到S3迴歸故宮
<form action="/user/fileUpload" enctype="multipart/form-data" class="ui form" method="post">
<div class="field">
<select class="ui dropdown">
<option value="">Print Agency</option>
<option value="fastprint">Fast Print</option>
<option value="printpress">Print Press</option>
</select>
</div>
<div class="field">
<input type="file" name="uploadFile" />
</div>
<div class="field">
<input type="submit" value="Upload" class="ui blue submit button" />
</div>
</form>
,這是將積極的,如果我按操作提交按鈕
fileUpload: function(req, res) {
req.file('uploadFile').upload({
adapter: require('skipper-s3'),
key: 'THE-KEY',
secret: 'THE-SECRET',
bucket: 'THE-BUCKET'
}, function (err, filesUploaded) {
if (err) {
console.log(err);
return res.negotiate(err);
}
return res.ok({
files: filesUploaded,
textParams: req.params.all()
});
});}
這是我的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>PUT</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>DELETE</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>
,這是我的S3鬥政策
{
"Version": "2012-10-17",
"Id": "Policy1433335661532",
"Statement": [
{
"Sid": "Stmt1433335656754",
"Effect": "Allow",
"Principal": "*",
"Action": [
"s3:DeleteObject",
"s3:GetObject",
"s3:PutObject"
],
"Resource": [
"arn:aws:s3:::BUCKET-NAME/*",
"arn:aws:s3:::BUCKET-NAME"
]
}
]
}
但總是導致禁止。我不知道爲什麼。 結果圖像:
,我真的需要在這裏你的幫助。
使用答案
思考@湯姆回答後更新我發現我多麼愚蠢我後,我知道這一切,因爲我忘了幾號線。
我應該把這個線內routes.js
'post /user/fileUpload': {
controller: 'UserController',
action: 'fileUpload'},
而且提交按鈕下面這一行,因爲我使用CSRF
<input type="hidden" name="_csrf" value="<%= _csrf %>" />
而此行內部UserController的行動文件上傳,波紋管「桶」
ACL: 'public-read'
Regards,
Elmer
你看到你的任何東西console.log(err)? – Meeker
@Meeker:沒有從console.log(err)..看來問題是S3權限。我已經授予每個人都可以列出和更新/刪除的權限。我也已經添加了COSR和桶策略 –