亚马逊S3上传什么键做

iSi*_*ign 3 file-upload amazon-s3

我真的很困惑,当使用亚马逊s3时,键值应该是什么,这是我的代码.

   <form action="http://bucket.s3.amazonaws.com" method="post" enctype="multipart/form-data">
<input type="text" name="key" value="{filename}" />
<input type="text" name="acl" value="public-read" />
<input type="text" name="content-type" value="text/plain" />
<input type="hidden" name="AWSAccessKeyId" value="Amazon Key" />
<input type="hidden" name="policy" value="ewogICJleHBpcmF0aW9uIjogIjIwMTItMDEtMDFUMTI6MDA6MDAuMDAwWiIsCiAgImNvbmRpdGlvbnMiOiBbCiAgICB7ImJ1Y2tldCI6ICJpcIHsiYWNsIjogInB1YmxpYy1yZWFkIiB9LAogICAgWyJlcSIsICIka2V5IiwgIntmaWxlbmFtZX0iXSwKICAgIFsic3RhcnRzLXdpdGgiLCAiJENvbnRlbnQtVHlwZSIsICJ0ZXh0LyJdLAogIF0KfQo=" />
<input type="hidden" name="signature" value="fGWi1jKU+hKZKbCIL1eD0=" />
<input name="file" type="file" />
<input name="submit" value="Upload" type="submit" />
</form>
Run Code Online (Sandbox Code Playgroud)

好吧我正在使用这项服务来生成我的政策等因为我还没有弄清楚如何手动完成这项工作.

http://s3.amazonaws.com/doc/s3-example-code/post/post_sample.html

这有效,并为我提供了上传的所有内容.但是当我上传我的文件时,他们总是调用{filename}而不是实际的文件名是picture.jpg.我知道这就是这条线.

<input type="text" name="key" value="{filename}" />
Run Code Online (Sandbox Code Playgroud)

我希望它从我上传的实际文件名中取出该值.

我做错了什么很困惑.

我试过把它留空但我得到这个错误.

InvalidArgumentUser键的长度必须大于0

我想让它为我工作????

请帮忙

Eys*_*Bye 6

我知道你很久以前发过这个问题,但有人可能有同样的问题.

Key是您要上传的文件的名称和路径.

您可以在策略中设置关于密钥的条件,例如它应该从哪个开始.您可以使用以下值保留原始文件名:$ {filename}(您缺少$)

示例:保留原始文件名,但放在文件夹/ docs /中

表格:

<form action="http://yourbucketname.s3.amazonaws.com" method="post" enctype="multipart/form-data">
<input type="text" name="key" value="docs/${filename}" />
<input type="text" name="acl" value="public-read" />
<input type="text" name="content-type" value="text/plain" />
<input type="hidden" name="AWSAccessKeyId" value="<YourPublicKey>" />
<input type="hidden" name="policy" value="<Base64_encoded_your_policy>" />
<input type="hidden" name="signature" value="<HMAC SHA-1 of the policy>" />
<input name="file" type="file" />
<input name="submit" value="Upload" type="submit" />
</form>
Run Code Online (Sandbox Code Playgroud)

该政策为JSON

{"expiration": "2013-12-01T12:00:00.000Z",
"conditions": [
{"acl": "public-read-write" },
{"bucket": "yourbucketname" },
["starts-with", "$key", "docs/"],
["starts-with", "$Content-Type", "text/plain"],
]
}
Run Code Online (Sandbox Code Playgroud)

你需要做什么: