Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

是否可以增加一个上传的endpoint? #64

Open
sanvibyfish opened this issue May 26, 2020 · 0 comments
Open

是否可以增加一个上传的endpoint? #64

sanvibyfish opened this issue May 26, 2020 · 0 comments

Comments

@sanvibyfish
Copy link

sanvibyfish commented May 26, 2020

背景是这样的,我在使用阿里云的OSS,机器的带宽有限,每次上传都是走公网的endpoint,如果上传大图就跪了。所以我希望上传的时候可以用内网的endpoint,然后获取service_url的时候是拿公网的host。

我目前使用的Rails版本是6.0

目前我的解决方案是这样的,个人感觉不是特别好。

# lib/active_storage_blob_extension.rb
module ActiveStorageBlobExtension
  extend ActiveSupport::Concern

  included do

    def cdn_service_url
      if ENV['CDN_HOST'].present?
        "#{ENV['CDN_HOST']}/#{self.key}"
      else
        self.service_url
      end 
    end

  end
end
# config/application.rb
...
    config.to_prepare do
      ActiveStorage::Blob.send :include, ::ActiveStorageBlobExtension
    end
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant