Rich_text 和 Active Storage S3 上传返回 200 但未上传文件
Rich_text and Active Storage S3 Uploads are returning 200 but not uploading the file
我在使用 rich_text 和 Active Storage 的 s3 附件时遇到一些问题。附件只是挂起而从未实际上传,S3 存储桶中没有文件。当我附加时,我得到这样的回复:
Started POST "/rails/active_storage/direct_uploads" for ::1 at 2020-11-18 07:15:08 -0800
Processing by ActiveStorage::DirectUploadsController#create as JSON
Parameters: {"blob"=>{"filename"=>"[FILTERED]", "content_type"=>"application/pdf", "byte_size"=>72922, "checksum"=>"fsKWzt9ogXiN21nveUYF5g=="}, "direct_upload"=>{"blob"=>{"filename"=>"[FILTERED]", "content_type"=>"application/pdf", "byte_size"=>72922, "checksum"=>"fsKWzt9ogXiN21nveUYF5g=="}}}
(0.3ms) BEGIN
ActiveStorage::Blob Create (13.2ms) INSERT INTO "active_storage_blobs" ("key", "filename", "content_type", "byte_size", "checksum", "created_at") VALUES (, , , , , ) RETURNING "id" [["key", "[present]"], ["filename", "Approved Lenders Washington 6.18.pdf"], ["content_type", "application/pdf"], ["byte_size", 72922], ["checksum", "fsKWzt9ogXiN21nveUYF5g=="], ["created_at", "2020-11-18 15:15:09.182618"]]
(22.5ms) COMMIT
S3 Storage (2.5ms) Generated URL for file at key: [present] (https://[bucket-name].s3.us-west-2.amazonaws.com/...)
Completed 200 OK in 1024ms (Views: 0.4ms | ActiveRecord: 48.9ms | Allocations: 150095)
我的模型,storage.yml & development.rb:
model.rb
class Exercise
has_rich_text :description
end
storage.yml
amazon:
service: S3
access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
region: us-west-2
bucket: <%= Rails.application.credentials.dig(:aws, :bucket_name) %>
development.rb
config.active_storage.service = :amazon
有什么可能出错的想法吗?提前致谢。
编辑:添加模型
CORS 配置在 S3 存储桶中的格式不正确。我将 CORS 配置修改为以下内容:
[
{
"AllowedHeaders": [
"*"
],
"AllowedMethods": [
"PUT",
"POST",
"DELETE"
],
"AllowedOrigins": [
"*"
],
"ExposeHeaders": [
"ETag"
],
"MaxAgeSeconds": 3000
}
]
我在使用 rich_text 和 Active Storage 的 s3 附件时遇到一些问题。附件只是挂起而从未实际上传,S3 存储桶中没有文件。当我附加时,我得到这样的回复:
Started POST "/rails/active_storage/direct_uploads" for ::1 at 2020-11-18 07:15:08 -0800
Processing by ActiveStorage::DirectUploadsController#create as JSON
Parameters: {"blob"=>{"filename"=>"[FILTERED]", "content_type"=>"application/pdf", "byte_size"=>72922, "checksum"=>"fsKWzt9ogXiN21nveUYF5g=="}, "direct_upload"=>{"blob"=>{"filename"=>"[FILTERED]", "content_type"=>"application/pdf", "byte_size"=>72922, "checksum"=>"fsKWzt9ogXiN21nveUYF5g=="}}}
(0.3ms) BEGIN
ActiveStorage::Blob Create (13.2ms) INSERT INTO "active_storage_blobs" ("key", "filename", "content_type", "byte_size", "checksum", "created_at") VALUES (, , , , , ) RETURNING "id" [["key", "[present]"], ["filename", "Approved Lenders Washington 6.18.pdf"], ["content_type", "application/pdf"], ["byte_size", 72922], ["checksum", "fsKWzt9ogXiN21nveUYF5g=="], ["created_at", "2020-11-18 15:15:09.182618"]]
(22.5ms) COMMIT
S3 Storage (2.5ms) Generated URL for file at key: [present] (https://[bucket-name].s3.us-west-2.amazonaws.com/...)
Completed 200 OK in 1024ms (Views: 0.4ms | ActiveRecord: 48.9ms | Allocations: 150095)
我的模型,storage.yml & development.rb:
model.rb
class Exercise
has_rich_text :description
end
storage.yml
amazon:
service: S3
access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
region: us-west-2
bucket: <%= Rails.application.credentials.dig(:aws, :bucket_name) %>
development.rb
config.active_storage.service = :amazon
有什么可能出错的想法吗?提前致谢。
编辑:添加模型
CORS 配置在 S3 存储桶中的格式不正确。我将 CORS 配置修改为以下内容:
[
{
"AllowedHeaders": [
"*"
],
"AllowedMethods": [
"PUT",
"POST",
"DELETE"
],
"AllowedOrigins": [
"*"
],
"ExposeHeaders": [
"ETag"
],
"MaxAgeSeconds": 3000
}
]