Ok, so. I'm having a bit of an issue with a `:...
# avo-2
c
Ok, so. I'm having a bit of an issue with a
:file
field. Avo is setting
ActiveStorage::Current.url_options
which is fine in development, where I'm using
disk
for the storage type, but for staging/production, this results in a URL to the Rails app itself instead of to the relevant S3 bucket. I assume I'm missing some obvious bit of configuration but I... don't know what it is. Can anyone point me in the right direction?
m
Thread automatically created by mrjoy in #740893011994738751
c
Strangely enough, this is only an issue for one attachment type. I have a
has_one_attached
image attachment which is what's busted, and a
has_many_attached
for more arbitrary files and... that one seems to be fine.
In the latter case, Avo is giving me an HMAC'd URL to the S3 bucket (hooray!), as I would expect. It's just... not doing this for the image attachment.
The image attachment field is declared:
field :profile_photo, as: :file, hide_on: %i[index], accept: "image/*", is_image: true
The documents field is declared:
Copy code
field :documents,
        as:                      :files,
        hide_on:                 %i[index],
        view_type:               :list,
        hide_view_type_switcher: true,
        accept:                  Analyzer::LinkedInAnalyzer::ALLOWED_TYPES.join(",")
Might be worth noting that there's different S3 buckets involved. The
stage.yml
(ActiveStorage config) looks like this:
Copy code
bio_data:
  service: S3
  bucket: <%= ENV.fetch("DOCUMENTS_BUCKET", "dummy") %>
  region: <%= ENV.fetch("DOCUMENTS_BUCKET_REGION", "us-east-1") %>

profile_photos:
  service: S3
  bucket: <%= ENV.fetch("PROFILES_BUCKET", "dummy") %>
  region: <%= ENV.fetch("PROFILES_BUCKET_REGION", "us-east-1") %>
And the relevant ActiveRecord incantations:
Copy code
has_many_attached :documents, service: :bio_data
  has_one_attached :profile_photo, service: :profile_photos
In the case of profile_photo, I have a broader issue with how to get a URL of the form
https://profile.sixty.app/<id>
instead of an HMAC'd URL since the contents are very intentionally public but that's a general I-don't-understand-ActiveStorage-yet issue, and not super relevant in the context of Avo.
l
> this results in a URL to the Rails app itself instead of to the relevant S3 bucket this is how Active storage works. it produces a rails URL which redirects to the s3 bucket
c
TY.
l
if you can create a reproduction repo we'd love to check it out
c
It seems like this is all down to me just misunderstanding and/or misconfiguring ActiveStorage. Nothing for you folks to check out. I do appreciate your diligence, though!