直接上传到使用AJAX亚马逊S3 [英] Upload Directly to amazon S3 using AJAX

查看:450
本文介绍了直接上传到使用AJAX亚马逊S3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想上载从浏览器的文件到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

任何帮助将大大AP preciated。

any help would be greatly appreciated.

感谢

编辑:这里是code请检查

here is the code pls check

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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