Reputation: 124
I am having some issues with rich_text and Active Storage's s3 attachments. The attachments just hang and never actually upload, no files in S3 bucket. When I attach, I get this response:
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 ($1, $2, $3, $4, $5, $6) 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)
My model, 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
Any ideas of what can be going wrong? Thanks in advance.
Edit: Add model
Upvotes: 1
Views: 359
Reputation: 124
The CORS configuration was not properly formatted in the S3 bucket. I modified the CORS configuration to below:
[
{
"AllowedHeaders": [
"*"
],
"AllowedMethods": [
"PUT",
"POST",
"DELETE"
],
"AllowedOrigins": [
"*"
],
"ExposeHeaders": [
"ETag"
],
"MaxAgeSeconds": 3000
}
]
Upvotes: 1