2013-01-19 360 views
3

我想上傳圖片到亞馬遜S3。我使用Carrierwave成功了。然後我切換到jQuery多圖像上傳。繼railscast 383.上傳到亞馬遜S3

我的upload_helper外觀與上圖完全相同;除了初始化方法。 https://github.com/railscasts/383-uploading-to-amazon-s3/blob/master/gallery-jquery-fileupload/app/helpers/upload_helper.rb

以下是在頁面用戶可以上傳他們的圖片:

= s3_uploader_form post: items_url, as: "painting[image_url]" do 
     = file_field_tag :file, multiple: true 

    %script#template-upload{type: "text/x-tmpl"} 
     .upload 
      {%=o.name%} 
      .progress 
       .bar{ style: "width: 0%" } 

我有以下JS太:

//= require jquery-fileupload/basic 
//= require jquery-fileupload/vendor/tmpl 
//= require paintings 

,因爲它是本教學中

即使我的S3上傳與carrierwave和單個文件上傳工作正常我得到

failed to upload image error (coming from the last line in paintings.js.coffee). and 
Failed to load resource: the server responded with a status of 400 (Bad Request) 

<Error> 
    <Code>AccessDenied</Code> 
    <Message>Access Denied</Message> 
    <RequestId>XYZ</RequestId> 
    <HostId> 
     XYZ 
    </HostId> 
</Error> 

我CORS的配置是:

<?xml version="1.0" encoding="UTF-8"?> 
<CORSConfiguration> 
    <CORSRule> 
     <AllowedOrigin>http://localhost:3000</AllowedOrigin> 
     <AllowedMethod>GET</AllowedMethod> 
     <AllowedMethod>POST</AllowedMethod> 
     <MaxAgeSeconds>3000</MaxAgeSeconds> 
     <AllowedHeader>*</AllowedHeader> 
    </CORSRule> 
</CORSConfiguration> 

任何指導是非常讚賞

回答

4

找到它!

在upload_helper> S3Uploader> initialze添加一個時區到你的 '過期:' 是這樣的:

expiration: 10.hours.from_now.utc, 

這確實神奇,我

好運