Ruby on rails Carrierwave_Direct与Jquery文件上传赢得';由于跨源请求,无法重定向
我正在集成Carrierwave_Direct和Jquery文件上传。一切正常。文件直接上传到S3,没有错误。但是,浏览器无法使用键参数(如)将用户重定向到新urlRuby on rails Carrierwave_Direct与Jquery文件上传赢得';由于跨源请求,无法重定向,ruby-on-rails,amazon-s3,carrierwave,cors,jquery-file-upload,Ruby On Rails,Amazon S3,Carrierwave,Cors,Jquery File Upload,我正在集成Carrierwave_Direct和Jquery文件上传。一切正常。文件直接上传到S3,没有错误。但是,浏览器无法使用键参数(如)将用户重定向到新url http://example.com?bucket=your_fog_directory&key=uploads%2Fguid%2Ffile.ext&etag=%22d41d8cd98f00b204e9800998ecf8427%22 在js控制台上,错误消息为 XMLHttpRequest cannot load https://
http://example.com?bucket=your_fog_directory&key=uploads%2Fguid%2Ffile.ext&etag=%22d41d8cd98f00b204e9800998ecf8427%22
在js控制台上,错误消息为
XMLHttpRequest cannot load https://example.s3.amazonaws.com/.
The request was redirected to 'http://example.com/users/settings?bucket=example&key=uploads…F1389525416-2-3762%2Fexample.jpg&etag=%225a44c7ba5bbe4ec867233d67e4806848%22',
which is disallowed for cross-origin requests that require preflight.
我已经在S3上设置了CORS:
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>http://example.herokuapp.com</AllowedOrigin>
<AllowedOrigin>http://localhost:3000</AllowedOrigin>
<AllowedMethod>PUT</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>DELETE</AllowedMethod>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
</CORSRule>
请提供帮助,提前感谢。以下是启用CORS for rails应用程序的方法: 档案:
gem 'rack-cors'
config.ru(在文件底部添加):
也遇到了这个问题,无法使重定向正常工作,即使在添加机架/COR并允许所有操作之后也是如此。相反,我最终使用了action_status而不是重定向。这将返回一个包含必要信息(键)的XML文档,然后您可以自己处理这些信息 必要的修改如下 在Carrierwave配置中:
config.use_action_status = true
设置上载程序时,请更改:
uploader.success_action_redirect = url
到
在表格中,添加:
= f.file_field :voter_file, :use_action_status => true
然后,在Javascript(或coffeescript)中:
希望有帮助。我也有同样的问题。您最终找到答案了吗?在carrierwave/fog中,您可以指定(强制)一个https调用“:s3_protocol=>:https”,并将您对aws的调用设置为https,这样您就可以了。当我调用http并呈现https(或其他方式)时,总是会遇到这种情况。您是否尝试在post方法上设置*并查看是否有效?我可能是第一条规则中双重允许起源的原因。另外,试着看看为什么它会重定向到example.com..因为规则在任何地方都没有提到这个url
uploader.success_action_redirect = url
uploader.success_action_status = "201" # must be a string, or S3 throws errors
= f.file_field :voter_file, :use_action_status => true
form.fileupload
dataType: 'xml'
success: (retdata) ->
# deal with the xml