【发布时间】:2016-06-02 01:30:57
【问题描述】:
我正在尝试让 S3 HTML 上传工作,我正在尝试硬编码定义键名,而不是使用 ${filename}。这是由我的 API 服务器控制的,但是当我指定一个带有文件夹分隔符的密钥并上传它时,它会转换为它的 html 实体 %2F。
所以我有这个 POST 政策:
{
"expiration": "2017-01-01T00:00:00Z",
"conditions": [
{"bucket": "mybucket"},
{"key": "i/1/1.png"},
{"acl": "public-read"},
{"Content-Type": "image/png"},
["content-length-range", "0", "1048576"]
]
}
这样使用 HTML 表单:
<html>
<head>
<title>S3 POST Form</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<form action="https://mybucket.s3.amazonaws.com/" method="post" enctype="multipart/form-data">
<input type="hidden" name="key" value="i/1/1.png">
<input type="hidden" name="AWSAccessKeyId" value="AWS_ACCESS_KEY_ID">
<input type="hidden" name="acl" value="public-read">
<input type="hidden" name="policy" value="base64 policy">
<input type="hidden" name="signature" value="signature">
<input type="hidden" name="Content-Type" value="image/png">
<!-- Include any additional input fields here -->
File to upload to S3:
<input name="file" type="file">
<br>
<input type="submit" value="Upload File to S3">
</form>
</body>
</html>
上传文件后,文件名如下:
https://mybucket.s3.amazonaws.com/i%2F1%2F1.png
所以问题是,我如何让 / 成为文字文件夹分隔符?
【问题讨论】: