Amazon S3 参数无效错误代码

Kin*_*mon 0 amazon-s3 amazon-web-services angularjs ng-file-upload

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

控制器.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) {

            });
Run Code Online (Sandbox Code Playgroud)

科尔斯配置

<?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>
Run Code Online (Sandbox Code Playgroud)

这是我收到的错误报告

  <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>
Run Code Online (Sandbox Code Playgroud)

任何帮助表示赞赏。

谢谢

Kin*_*mon 5

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

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

          });
Run Code Online (Sandbox Code Playgroud)