Rails 5.2 Active Storage直接上传失败:CORS标头"Access-Control-Allow-Origin"丢失 [英] Rails 5.2 Active Storage direct upload failure: CORS header ‘Access-Control-Allow-Origin’ missing

查看:59
本文介绍了Rails 5.2 Active Storage直接上传失败:CORS标头"Access-Control-Allow-Origin"丢失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在试用Rail 5.2.0.rc1 Active Storage,使用其随附的JavaScript库将PDF文档直接从客户端上传到云.但是在提交表单时,我在Firefox&Chrome:

I am trying out Rail 5.2.0.rc1 Active Storage, using its included JavaScript library to upload PDF docs directly from the client to the cloud. But on submitting a form I get a browser error in both Firefox & Chrome:

Cross-Origin Request Blocked... (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).

因此设置了标头,因此位于activestorage.js中的this.xhr.setRequestHeader ...似乎不是可配置的:

Headers are set thus this.xhr.setRequestHeader... in the activestorage.js and dont appear to be configurable: https://github.com/rails/rails/blob/master/activestorage/app/javascript/activestorage/blob_record.js

有任何建议吗?

推荐答案

尝试使用以下命令在S3存储桶上设置CORS权限:

Try setting the CORS permission on the S3 bucket with the following:

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
    <AllowedOrigin>*</AllowedOrigin>
    <AllowedMethod>GET</AllowedMethod>
    <MaxAgeSeconds>3000</MaxAgeSeconds>
    <AllowedHeader>Authorization</AllowedHeader>
</CORSRule>
<CORSRule>
    <AllowedOrigin>*</AllowedOrigin>
    <AllowedMethod>PUT</AllowedMethod>
    <AllowedMethod>POST</AllowedMethod>
    <MaxAgeSeconds>3000</MaxAgeSeconds>
    <AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>

这篇关于Rails 5.2 Active Storage直接上传失败:CORS标头"Access-Control-Allow-Origin"丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆