Active Storage 多租户应用程序中附件的无效链接

问题描述 投票:0回答:0

我正在使用 apartment gem 开发一个多租户应用程序,我的附件正在成功上传。

我可以找到它

document = Document.first
document.attachment.attached? = #true
document.attachment.blob

# id: 122,
# key: "fq6my0hzl2oooivq3mimzeao0",
# filename: "sample.pdf",
# content_type: "application/pdf",
# metadata: {"identified"=>true, "analyzed"=>true},
# service_name: "local",
# byte_size: 10635049,
# checksum: "TlJvqtVg1DPDaKOKpA==",
# created_at: Thu, 06 Apr 2023 19:09:45.179014000 UTC +00:00>

我正在生成 URL

def get_attachment_url_for(attachment_field_name)
  attachment = try(attachment_field_name.to_s)
  url = Rails.application.routes.url_helpers.rails_blob_path(attachment, only_path: true)

  ::DEFAULT_HOST + url
end

我从上面的代码得到的 URL 就像

`http://localhost:3000`/rails/active_storage/blobs/redirect/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBmdz09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--b5d0202877ed171bf1b3a1cafebec/sample.pdf

但是当我在 Chrome 选项卡中打开它时,我没有路由匹配我尝试在本地主机之前添加我的子域前缀

http://my-subdomain.localhost:3000/...........

但面临同样的问题

我的storage.yml是

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

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

staging:
  service: Disk
  root: <%= Rails.root.join("storage") %>
ruby-on-rails multi-tenant rails-activestorage ruby-on-rails-7
© www.soinside.com 2019 - 2024. All rights reserved.