我试图将mp3文件上传到我的S3存储桶。我在某处读到,最好的方法是将文件从html表单直接上传到S3,而无需通过服务器进行管道传输。但我想知道:这种方法安全吗?出于安全原因,是否需要服务器,例如应用访问密钥等?
此外,我发现很难让它发挥作用。我认为官方解释并不十分详细。
我遵循本指南:http://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-post-example.html这是官方指南。我不确定我做得对。如果这是正确的方式以及我做错了什么,请你告诉我:
1。我填写了一个Policy对象
{ "expiration": "2015-12-30T12:00:00.000Z",
"conditions": [
{"bucket": "sigv4examplebucket"},
["starts-with", "$key", "user/user1/"],
{"acl": "public-read"},
{"success_action_redirect": "http://sigv4examplebucket.s3.amazonaws.com/successful_upload.html"},
["starts-with", "$Content-Type", "image/"],
{"x-amz-meta-uuid": "14365123651274"},
{"x-amz-server-side-encryption": "AES256"},
["starts-with", "$x-amz-meta-tag", ""],
{"x-amz-credential": "AKIAIOSFODNN7EXAMPLE/20151229/us-east-1/s3/aws4_request"},
{"x-amz-algorithm": "AWS4-HMAC-SHA256"},
{"x-amz-date": "20151229T000000Z" }
]
}
2。我base64编码策略对象
第3。我使用上传表格制作HTML页面
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<form action="http://sigv4examplebucket.s3.amazonaws.com/" method="post" enctype="multipart/form-data">
Key to upload:
<input type="input" name="key" value="user/user1/${filename}" /><br />
<input type="hidden" name="acl" value="public-read" />
<input type="hidden" name="success_action_redirect" value="http://sigv4examplebucket.s3.amazonaws.com/successful_upload.html" />
Content-Type:
<input type="input" name="Content-Type" value="image/jpeg" /><br />
<input type="hidden" name="x-amz-meta-uuid" value="14365123651274" />
<input type="hidden" name="x-amz-server-side-encryption" value="AES256" />
<input type="text" name="X-Amz-Credential" value="AKIAIOSFODNN7EXAMPLE/20151229/us-east-1/s3/aws4_request" />
<input type="text" name="X-Amz-Algorithm" value="AWS4-HMAC-SHA256" />
<input type="text" name="X-Amz-Date" value="20151229T000000Z" />
Tags for File:
<input type="input" name="x-amz-meta-tag" value="" /><br />
<input type="hidden" name="Policy" value='<Base64-encoded policy string>' />
<input type="hidden" name="X-Amz-Signature" value="<signature-value>" />
File:
<input type="file" name="file" /> <br />
<!-- The elements after this will be ignored -->
<input type="submit" name="submit" value="Upload to Amazon S3" />
</form>
</body>
</html>
答案 0 :(得分:0)
您正在寻找的是AWS S3预签名网址。基本上,步骤是:
1)服务器生成预先签名的URL(因为它有aws密钥)
2)服务器将此预先签名的网址传递给浏览器
3)浏览器可以通过此预先签名的URL
直接将文件上传到s3参考:http://docs.aws.amazon.com/AmazonS3/latest/dev/PresignedUrlUploadObject.html