2015-09-03 45 views
0

我想上傳文件圖像到我的亞馬遜s3存儲桶,但不斷收到400錯誤的請求錯誤。在挖掘我發現錯誤代碼是無效的參數,但我不知道爲什麼我不斷收到錯誤。亞馬遜S3無效的參數錯誤代碼

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

任何幫助表示讚賞。

謝謝

+0

請捕捉響應主體並將其添加到問題中。 –

+0

@ Michael-sqlbot在錯誤報告中添加了 –

+0

@KingsleySimon您是否得到了修正?這個問題是什麼? – Katana24

回答

0

CORS S3亞馬遜文件夾中的配置。

請檢查並看看您的標題中發送的內容是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> 
3

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

      }); 
+0

您是否也在Github上發佈了這個問題?我想我在那裏看到了相同的代碼。沒有,這沒有幫助我,這表明它不是頭問題。無論如何,謝謝 – Katana24

+0

@ Katana24你會得到什麼錯誤? –