Kev*_*dal 3 html file-upload amazon-s3 asp.net-mvc-4 url-redirection
我一直在努力将文件直接从html表单上传到Amazon S3存储桶并使其正常工作,但在成功上传后它不会重定向.我正在发送'success_action_redirect'字段,并且正在获取204状态代码(yay).我的想法是它没有认识到重定向到localhost(我正在测试的地方),但即使我把www.google.com作为重定向,它也不会重定向.
这是我编码到我的签名中的json(日期是临时的):
{
"expiration": "2014-01-01T00:00:00Z",
"conditions":
[
{"bucket": "mybucket"},
["starts-with", $key, "tests/" ],
{"success_action_redirect": "www.google.com"},
{"acl": "public-read" }
]
}
Run Code Online (Sandbox Code Playgroud)
这是我的html:
<form id="fileform" action="https://mybucket.s3.amazonaws.com/" method="post" enctype="multipart/form-data" >
<input type="hidden" name="key" value="@key" />
<div class="editor-area">
<label for="file">File</label>
<input type="file" name="file" />
</div>
<input type="hidden" name="success_action_redirect" value="www.google.com" />
<input type="hidden" name="acl" value="public-read" />
<input type="hidden" name="AWSAccessKeyId" value="@awsAccessKeyId" />
<input type="hidden" name="policy" value="@b64Policy" />
<input type="hidden" name="signature" value="@signature" />
<button id="file-button">Save File</button>
</form>
Run Code Online (Sandbox Code Playgroud)
这是有效的,它只是没有进行重定向(我的CORS设置都设置为接受帖子).是否存在必须设置为允许重定向的CORS设置?
如果有人能看到我可能做错了什么,请赐教!
我遇到了同样的问题,发现你的问题很遗憾,没有答案.但是,在重新阅读文档后,我解决了在成功上传到S3存储桶后没有发生重定向的问题.事实证明,我错过了S3文档上的一个小片段,看起来它可能会导致您的问题......
http://docs.aws.amazon.com/AmazonS3/latest/dev/HTTPPOSTForms.html#HTTPPOSTFormFields
文件或内容必须是表单中的最后一个字段.它下面的任何字段都会被忽略.
在我的表单中,我在文件输入字段后面有隐藏的重定向输入字段,因此S3忽略了它.在我的文件字段之前移动隐藏的重定向输入字段可以解决问题.现在我的帖子重定向到指定的重定向.
我不正确的表格:
<form action="http://<bucketName>.s3.amazonaws.com/" method="post"
enctype="multipart/form-data">
<input type="hidden" name="key" value="${filename}" />
<input type="file" name="file" />
<!-- the following fields are ignored as they are after the file field -->
<input type="hidden" name="success_action_redirect"
value="http://www.google.com/" />
<input type="submit" value="send to aws" />
</form>
Run Code Online (Sandbox Code Playgroud)
我的纠正和工作形式:
<form action="http://<bucketName>.s3.amazonaws.com/" method="post"
enctype="multipart/form-data">
<input type="hidden" name="key" value="${filename}" />
<input type="hidden" name="success_action_redirect"
value="http://www.google.com/" />
<input type="file" name="file" />
<input type="submit" value="send to aws" />
</form>
Run Code Online (Sandbox Code Playgroud)
所以对于你的例子,我会尝试以下内容:
<form id="fileform" action="https://mybucket.s3.amazonaws.com/" method="post" enctype="multipart/form-data" >
<input type="hidden" name="key" value="@key" />
<input type="hidden" name="success_action_redirect" value="http://www.google.com/" />
<input type="hidden" name="acl" value="public-read" />
<input type="hidden" name="AWSAccessKeyId" value="@awsAccessKeyId" />
<input type="hidden" name="policy" value="@b64Policy" />
<input type="hidden" name="signature" value="@signature" />
<div class="editor-area">
<label for="file">File</label>
<input type="file" name="file" />
</div>
<button id="file-button">Save File</button>
</form>
Run Code Online (Sandbox Code Playgroud)
注意:我确实更新了URL以包含协议
| 归档时间: |
|
| 查看次数: |
1773 次 |
| 最近记录: |