在生产环境中,我的后台办公室/ admin收到Direct_upload错误404
我已逐步遵循Rails教程
我已将direct_uploads放入javascript / utils
在application.js中,我添加了:
import * as activeStorage from "activestorage";
import "../utils/direct_uploads.js"
在production.rb中添加前缀:config.active_storage.routes_prefix = '/img'
当我要上传图片时,出现错误404:
无法加载资源:服务器的状态为404()=> / img / direct_uploads
和
从原点“ https://example.com/img/direct_uploads”到“ https://www.example.com”处对XMLHttpRequest的访问已被CORS策略阻止:对预检请求的响应未通过访问控制检查:否'access-Control-Allow-来源的标头出现在请求的资源上。
我在S3中的cors配置:
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>https://*.example.com</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>Authorization</AllowedHeader>
</CORSRule>
<CORSRule>
<AllowedOrigin>https://*.example.com</AllowedOrigin>
<AllowedMethod>PUT</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>
编辑:。
我添加了宝石“ rack-cors”,现在得到错误422
XHR finished loading: OPTIONS "https://example.com/img/direct_uploads"
"https://example.com/img/direct_uploads".
XHR failed loading: POST "https://example.com/img/direct_uploads".