使用POST请求在AWS S3上基于浏览器的文件上传 [英] Browser Based File Upload on AWS S3 using POST Request
问题描述
这是我的HTML POST表单.
This is my HTML POST Form.
<html>
<head>
<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>
</html>
我是从下面显示的AWS S3 Docs中获得的.
I got this from the AWS S3 Docs shown below.
https://docs.aws.amazon .com/AmazonS3/latest/API/sigv4-post-example.html
我从AWS控制台获得了如下所示的安全凭证.
From AWS Console I have gotten my security credentials as shown below.
我知道我需要为策略"和"X-Amz签名"设置值,但是我不确定如何做到这一点.
I am aware that I need to set values for "Policy" and "X-Amz-Signature" but I am not sure as to how to do that.
他们在文档中提到我需要StringToSign并获取策略/签名,但是我不确定如何做到这一点.
In the docs they have mentioned that I need to StringToSign and get the Policy/Signature but I am not sure how to do that.
有人可以帮助我如何为我的HTML表单生成策略和签名吗?
Can someone help me as to how to generate Policy and Signature for my HTML FORM ?
推荐答案
You will have to calculate the signature from backend. Follow these details Calculating a Signature to implement at your own.
类似于
或者您可以使用您选择的任何 AWS SDK . Or you can use any of the AWS SDKs of your choice. 例如,使用
查看全文