0

我正在尝试将文件图像上传到我的 Amazon s3 存储桶,但不断收到 400 Bad request 错误。在挖掘时我发现错误代码是 Invalid Argument 但我不知道为什么我不断收到错误。

控制器.js

 Upload.upload({
              url: url,
              method: 'POST',
              fields : {
                key: imageURI.name,
                AWSAccessKeyId: key,
                acl: 'public-read',
                policy: policy,
                signature: signature, 
                "Content-Type": imageURI.type != '' ? imageURI.type : 'application/octet-stream',
                filename: imageURI.name
              },
              file: imageURI,
            }).success(function(data, status, headers, config) {
                console.log(data);
                console.log(headers);
            }).error(function (data, status, headers, config) {

            });

cors配置

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
    <CORSRule>
        <AllowedOrigin>http://localhost:8100</AllowedOrigin>
        <AllowedOrigin>http://staging.com.my</AllowedOrigin>
        <AllowedOrigin>http://partners.com.my</AllowedOrigin>
        <AllowedMethod>PUT</AllowedMethod>
        <MaxAgeSeconds>3000</MaxAgeSeconds>
        <AllowedHeader>*</AllowedHeader>
    </CORSRule>
</CORSConfiguration>

这是我得到的错误报告

  <Error>
    <Code>InvalidArgument</Code>
    <Message>Authorization header is invalid -- one and only one ' ' (space) required</Message>
    <ArgumentName> Authorization</ArgumentName>
    <ArgumentValue>YrRHhyr9uDF5SYntzyR3</ArgumentValue>
    <RequestId>94E78E47B15BE7C5</RequestId>
 <HostId>eR/Smasry6u1tE5b3DfrTLSGve3y4a/dZlYMLnBjcC2YhjUzskLzu3q85SYdfb9q0Ii09HCWcSI=</HostId>
    </Error>

任何帮助表示赞赏。

谢谢

4

2 回答 2

4

@Katana24 试试这个。有可能在您的标头中发送了 Authorization 的值,因此您必须将其删除。有时这样做之后它仍然会给你一个错误,所以你将它分配给未定义的。希望这对您有用,如果有效,请标记为答案。干杯

          Upload.upload({
            url: "https://partners-mobile-app.s3.amazonaws.com/", //S3 upload url including bucket name
            method: 'POST',
            transformRequest: function (data, headersGetter) {
             //Headers change here
              var headers = headersGetter();
              delete headers['Authorization'];
              return data;
            },
            headers: {
              'Authorization': undefined
            },
            fields : {
                key: imageURI.name,
                AWSAccessKeyId: key,
                acl: 'public-read',
                policy: policy,
                signature: signature, 
                "Content-Type": imageURI.type != '' ? imageURI.type : 'application/octet-stream',
                filename: imageURI.name
              },
              file: imageURI,
            }).success(function(data, status, headers, config) {
                console.log(data);
                console.log(headers);
            }).error(function (data, status, headers, config) {

          });
于 2016-02-16T11:08:38.840 回答
0

S3 Amazon 文件夹中的 CORS 配置。

请检查并查看您的标头中发送到 S3 的内容,您在标头中发送“Content-Type”。将其包含在 cors 配置中。检查这个样本。

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
    <CORSRule>
        <AllowedOrigin>*</AllowedOrigin>
        <AllowedMethod>POST</AllowedMethod>
        <AllowedMethod>GET</AllowedMethod>
        <AllowedMethod>PUT</AllowedMethod>
        <AllowedMethod>DELETE</AllowedMethod>
        <MaxAgeSeconds>3000</MaxAgeSeconds>
        <AllowedHeader>Authorization</AllowedHeader>
        <AllowedHeader>Content-Type</AllowedHeader>
    </CORSRule>
</CORSConfiguration>
于 2015-09-21T10:41:57.407 回答