我正在尝试将图片上传到亚马逊 S3。我成功使用了carrierwave。然后我切换到 jQuery 多图像上传。在railscast 383之后。
我的 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>
非常感谢任何指导