2013-01-19 311 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, 

这确实神奇,我

好运