使用AJAX返回错误直接上传到亚马逊S3:存储桶POST必须包含一个名为"key"的字段 [英] Upload Directly to amazon S3 using AJAX returning error: Bucket POST must contain a field named 'key'

查看:499
本文介绍了使用AJAX返回错误直接上传到亚马逊S3:存储桶POST必须包含一个名为"key"的字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将文件从浏览器上传到s3亚马逊,我已经修改了CORS策略规则,以允许在存储桶中发布帖子,但是我遇到了错误

I'm trying to upload files from browser to s3 amazon, I've modified the CORS policy rules to allow the post for the bucket, but I'm getting the error

    <?xml version="1.0" encoding="UTF-8"?>
    <Error><Code>InvalidArgument</Code><Message>Bucket POST must contain a field named 'key'.  If it is specified, please check the order of the fields.</Message>
<ArgumentValue></ArgumentValue><ArgumentName>key</ArgumentName><RequestId>1E0A8DC78C0CEA9A</RequestId><HostId>XN38Qje9hUrGqHNIhtT8CtowX9tXlpyfEoaXb1UNxlsyLOWreh2mKqKVXg1zjLVl</HostId></Error>

这是我的请求和响应,我仍会收到此错误,从而以正确的顺序传递了关键参数

Here is my request and response, I'm passing key parameter in the right order by still getting this error

谁能告诉我这是怎么回事,我正在使用FormData提交请求

Can anyone tell me whats wrong with it, I'm submitting request using FormData

任何帮助将不胜感激.

谢谢

这是请检查代码

var form_data = new FormData();         
                form_data.append('file',hdlr.file);
                //form_data.append('crop_type',settings.get_cropped_type());
                //form_data.append('attributes',JSON.stringify(file_attr));
                $('input:hidden',$form).each(function(){

                    form_data.append(this.name,this.value);

                });


                //finally post the file through AJAX  
                var xhr = new XMLHttpRequest();  
                xhr.open("POST", $form[0].action, true);  
                xhr.send(form_data);

推荐答案

看起来您的文件表单字段在请求中首先出现.我不确定,因为您没有在答案中包含整个请求有效负载,但是看起来好像出现在键"字段的上方. AWS会忽略请求中文件字段之后的所有字段,因此所有其他字段必须出现在文件之前.

It kind of looks like your file form field is appearing first in the request. I can't tell for sure since you have not included the entire request payload in your answer, but it looks like this is appearing just above the "key" field. AWS ignores all fields in the request after the file field, so all other fields must appear before the file.

这篇关于使用AJAX返回错误直接上传到亚马逊S3:存储桶POST必须包含一个名为"key"的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆