Initial commit
This commit is contained in:
21
app/uploaders/ali_uploader.rb
Normal file
21
app/uploaders/ali_uploader.rb
Normal file
@@ -0,0 +1,21 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'aliyun/oss'
|
||||
|
||||
class AliUploader < UploadUploader
|
||||
def url
|
||||
bucket.object_url(Barong::App.config.storage_bucket_name + '/' + path)
|
||||
end
|
||||
|
||||
def bucket
|
||||
@_bucket = client.get_bucket(Barong::App.config.storage_bucket_name)
|
||||
end
|
||||
|
||||
def client
|
||||
@_client ||= Aliyun::OSS::Client.new(
|
||||
endpoint: "oss-#{Barong::App.config.storage_region}.aliyuncs.com",
|
||||
access_key_id: Barong::App.config.storage_access_key,
|
||||
access_key_secret: Barong::App.config.storage_secret_key,
|
||||
)
|
||||
end
|
||||
end
|
||||
39
app/uploaders/upload_uploader.rb
Normal file
39
app/uploaders/upload_uploader.rb
Normal file
@@ -0,0 +1,39 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# It's for upload document for Document model
|
||||
class UploadUploader < CarrierWave::Uploader::Base
|
||||
# if Rails.env.production?
|
||||
# storage :fog
|
||||
# else
|
||||
# storage :file
|
||||
# end
|
||||
|
||||
# TODO just for alpha is file
|
||||
storage :file
|
||||
# Override the directory where uploaded files will be stored.
|
||||
# This is a sensible default for uploaders that are meant to be mounted:
|
||||
def store_dir
|
||||
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
|
||||
end
|
||||
|
||||
# Add a white list of extensions which are allowed to be uploaded.
|
||||
# For images you might use something like this:
|
||||
def extension_whitelist
|
||||
Barong::App.config.upload_extension_whitelist
|
||||
end
|
||||
|
||||
def size_range
|
||||
# default is 1..10.megabytes
|
||||
Barong::App.config.upload_size_min_range..Barong::App.config.upload_size_max_range.megabytes
|
||||
end
|
||||
|
||||
# Override default 'publicly visible' policy of fog
|
||||
def fog_public
|
||||
false # (default is true, which is not recommended for KYC documents or any user info
|
||||
end
|
||||
|
||||
# Set the expire time of authentification signature
|
||||
def fog_authenticated_url_expiration
|
||||
Barong::App.config.upload_auth_url_expiration.minutes # (default is 1.minute)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user