Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in AWS by (19.1k points)

rails version 5.2

I have a scenario that I need to access the public URL of Rails Active Storage with Amazon s3 to make a zip file with Sidekiq background job.

I am having difficulty getting the actual file URL. I have tried the following

rails_blob_url

but it gives me following

http://localhost:3000/rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBBZUk9IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--9598613be650942d1ee4382a44dad679a80d2d3b/sample.pdf

How do I access the real file URL through sidekiq?

storage.yml

 test:

  service: Disk

  root: <%= Rails.root.join("tmp/storage") %>

local:

  service: Disk

  root: <%= Rails.root.join("storage") %>

development:

  service: S3

  access_key_id: 'xxxxx'

  secret_access_key: 'xxxxx'

  region: 'xxxxx'

  bucket: 'xxxxx'

development.rb

  config.active_storage.service = :development

I can access fine these on web interface but not within the sidekiq

1 Answer

0 votes
by (44.4k points)

Use ActiveStorage::Blob#service_url. For instance,

@post.header_image.service_url

Related questions

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...