Ask A Question

Notifications

You’re not receiving notifications from this thread.

Blog Posts with File Uploads using ActiveStorage & Amazon S3 Discussion

How did you get to the Policy section on AWS?

Reply

Replying to self. I just copied the URL and got to the right page.

This walking through of how to set up AWS S3 was very helpful. I've done it before and sure I've made some (probably serious) errors.

Reply

The first ARN success, but the second failed and get an error "Entered ARN is invalid."
"learning-path-blog/*" did i make typo?

Reply
Reply

Thank you!!
Are you from Indonesia?

Reply

yea...

Reply

Wah berarti nggak perlu pakai bahasa inggris nih 😁
Salam kenal, aku juga dari Indonesia

Reply

Bagi github nya kita saling follow bang
github.com/ekowi

Reply

Udah aku follow bang
https://github.com/Lyriraki

Reply

I simply added the object access one line below that (where it's explicitly about objects, not the bucket). Don't know if that's correct, but it works.

Reply

Can I ask how? Tried to follow but still stuck as to what to add - for context what I have in the permissions policy editor right now is:

{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:GetObject",
"s3:ListBucket",
"s3:DeleteObject",
"s3:PutObjectAcl"
],
"Resource": "arn:aws:s3:::learning-path-blog-jon"
}
]
}

Reply

I would like to confirm what I am thinking. Action Text works with active storage so since I didn't install active storage seperately but did it through action text, I believe my active storage is set for me and doesn't need further configuration should I want to be uploading only images for my application?

Reply

Would appreciate some help - when I set the active_storage.service to :local, I am able to reproduce the same results as Chris did. But not with the service pointing at :amazon. I have setup the AWS S3 bucket with the same settings and all the configurations on the codebase. This is the error I get on the browser console:

Access to XMLHttpRequest at 'https://juliano-gorails-blog.s3.amazonaws.com/.....' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Reply

What caused this error for me were 2 things:

  1. My localhost domain was different (localhost instead of 127.0.0.1). I also had to make sure it's not accidentally https locally, because there will be no ssl. I had to make sure to get this right in the CORS policy.

  2. By default storage.yml names the bucket with the rails environment at the end (using some ERB). I kept it there, named my bucket "blabla-production" and of course got an error in "development" :P. Make sure your bucket name in storage.yml actually matches the name on S3.

Reply

Hello Chris and rails developers, for sure that was the most challenging part of this series of tutorials, In my case everything work as was explained but in production when I use render The image is uploaded but I can not see it. Maybe any idea about this problem.

Reply

Hey there I am Diego from the future, my problem was I use a image with SVG format, I don't go deep in the problem but apparently there are some image formats that don't work well I change to jpg and work as expected.

Reply

I'm getting KeyError in BlogPosts#index

'Missing configuration for the amazon Active Storage service. Configurations available for the test and local services.'

Reply

I'm dumb. In the storage.yaml file, '#amazon' also needs to be uncommented.

Reply

If you are receiving this error: "Token is invalid and failed to refresh."
Do this on your terminal:
aws configure --profile YOUR-PROFILE-NAME
AWS Access Key ID [None]: YOUR-ACCESS-KEY-ID
AWS Secret Access Key [None]: YOUR-SECRET-ACCESS-KEY
Default region name [None]: YOUR-REGION
Default output format [None]: json

to list:
aws configure list

Reply

In my case I also needed to update config.active_storage.service = :amazon
at config/environments/development.rb and config/environments/production.rb

Reply

Sorry missed that in video.

Reply

Hi , found problem with Action Text. For example, we have a blog model with a content field (action text field). We have attached the image (at this point it has been uploaded to amazon s3) and are not saving the blog. Result: We have a file on amazon s3 that is not tied to anything

Reply

Thank you Chris. Thank you very much for all your work.

Reply

This issue is currently plaguing this tutorial on updated rails and ruby. https://github.com/rails/rails/issues/52127

Reply

In case this might help anyone, I had to add both the 'http' and https' version of the Render URL to the CORS configuration for it to function properly.

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 86,796+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.