Skip to content

Commit

Permalink
Upload support :file ruby-china#794
Browse files Browse the repository at this point in the history
  • Loading branch information
huacnlee authored and Raincal committed Nov 17, 2016
1 parent 0a143cb commit c7d194f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
11 changes: 9 additions & 2 deletions app/uploaders/base_uploader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion config/config.yml.default
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions config/initializers/carrierwave.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c7d194f

Please sign in to comment.