开发者

Changing the sequence

I am trying to upload a file into my amazon account using the dojo.io.send.However, it's failing to do so .

This is error which i get to see when i run through the firebug.

<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>

I figured out the reason and apparently the "Key" field is below to the "File" field because of that it is ignoring below ones and throwing up the error .

In order to rectify this issue, i need to have dojo.io.send() to send the param's list in the following way:-

key uploads/${filename}
AWSAccessKeyId
policy
signature
Content-Type plain/text
file

I tried my luck by playing with the below code but it always put the file field on the top.

I would appreciate if anybody can help me out in changing the sequence.

Code Snippet:-

var jsonpArgs =
      {
            url: "https://s3.amazonaws.com/<Bucketname>",
            form : dojo.byId("Myform"),  
            //MyForm has an attribute
           //as file which takes the file name from the user to upload.

                     handleAs: "json",
                     content:
                     {
                            "key":"*******",
                            "AWSAccessKeyId":"****",
                            "policy" :"***********",
                            "signature":"******开发者_Go百科*",
                            "Content-Type":"plain/text"

                      },
                      error: function(error)
                      {

                      },


       };

 dojo.io.iframe.send(jsonpArgs);

      },

Appreciated,


The cause is that Dojo just iterate all the properties in the JSON object and generate the POST request body from it. Since the order of iteration is undetermined, you can not guarantee that the key property always is the first one.

The solution is to generate the POST body yourself. You can get the POST body string using:

"key=" + encodeURIComponent(key) + "&" + dojo.objectToQuery({AWSAccessKeyId : "", policy :""})

By doing this, the key is always the first one in the post body.

When sending the request, do not use content property, use rawBody instead. If you're using older version of Dojo, maybe you can use dojo.rawXhrPost and using postData property in the request.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜