Recently I built out a new model which utilizes ActionText and by extension ActiveStorage so that I can embed attachments and images.
However, when I tested it locally it didn't work. It left a cryptic error:
However, when I tested it locally it didn't work. It left a cryptic error:
failed to upload <image name> error code 0
I dug around, and found this post which indicated that perhaps my AWS S3 CORS configuration was to blame.
Sure enough, I was able to fix it by navigating to my S3 CORS settings located under the "Permissions" tab (https://us-east-1.console.aws.amazon.com/s3/buckets/<bucket name>?region=<region>&tab=permissions) and added this CORS configuration:
[ { "AllowedHeaders": [ "Content-Type", "Content-MD5", "Content-Disposition" ], "AllowedMethods": [ "PUT" ], "AllowedOrigins": [ "http://localhost:3000", "https://adamtaylor.me" ], "ExposeHeaders": [], "MaxAgeSeconds": 3600 } ]
After that, all my attachments worked correctly!