diff --git a/app/uploaders/base_uploader.rb b/app/uploaders/base_uploader.rb index c06e8a8322..941998f6d2 100644 --- a/app/uploaders/base_uploader.rb +++ b/app/uploaders/base_uploader.rb @@ -13,7 +13,11 @@ class BaseUploader < CarrierWave::Uploader::Base ALLOW_VERSIONS = %w(xs sm md lg large) def store_dir - model.class.to_s.underscore + dir = model.class.to_s.underscore + if Setting.upload_provider == 'file' + dir = "uploads/#{dir}" + end + dir end def extension_white_list @@ -28,8 +32,11 @@ def url(version_name = nil) raise "ImageUploader version_name:#{version_name} not allow." end - if Setting.upload_provider == 'aliyun' + case Setting.upload_provider + when 'aliyun' super(thumb: "@!#{version_name}") + when 'upyun' + [@url, version_name].join('!') else [@url, version_name].join('!') end diff --git a/config/config.yml.default b/config/config.yml.default index a20f49aeb7..9a561ce6c0 100644 --- a/config/config.yml.default +++ b/config/config.yml.default @@ -61,7 +61,7 @@ defaults: &defaults # (second) period: 180 asset_host: "" - upload_provider: "upyun" # can be upyun/aliyun + upload_provider: "upyun" # can be file/upyun/aliyun upload_access_id: "your-access-id" # or username upload_access_secret: "your-access-secret" # or upyun password upload_bucket: "your-bucket" diff --git a/config/initializers/carrierwave.rb b/config/initializers/carrierwave.rb index 5280a2e791..21e2ee2b77 100644 --- a/config/initializers/carrierwave.rb +++ b/config/initializers/carrierwave.rb @@ -42,5 +42,7 @@ def retrieve!(_identifier) config.upyun_password = Setting.upload_access_secret config.upyun_bucket = Setting.upload_bucket config.upyun_bucket_host = Setting.upload_url + else + config.storage = :file end end