我正在尝试将图片上传到亚马逊S3。我成功使用了carrierwave。然后我切换到jQuery多图像上传。关注railscast 383。
我的upload_helper看起来完全如图所示;除了initialize方法。 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>
非常感谢任何指导
答案 0 :(得分:4)
找到它!!!
在upload_helper&gt; S3Uploader&gt; initialze为你的'到期时间添加一个时区:'就像这样:
expiration: 10.hours.from_now.utc,
这为我带来了魔力
祝你好运