mirror of
https://github.com/discourse/discourse.git
synced 2024-12-18 18:24:56 +08:00
18 lines
593 B
Ruby
18 lines
593 B
Ruby
|
module LocalStore
|
||
|
|
||
|
def self.store_file(file, image_info, upload_id)
|
||
|
clean_name = Digest::SHA1.hexdigest("#{Time.now.to_s}#{file.original_filename}")[0,16] + ".#{image_info.type}"
|
||
|
url_root = "/uploads/#{RailsMultisite::ConnectionManagement.current_db}/#{upload_id}"
|
||
|
path = "#{Rails.root}/public#{url_root}"
|
||
|
|
||
|
FileUtils.mkdir_p path
|
||
|
# not using cause mv, cause permissions are no good on move
|
||
|
File.open("#{path}/#{clean_name}", "wb") do |f|
|
||
|
f.write File.read(file.tempfile)
|
||
|
end
|
||
|
|
||
|
# url
|
||
|
return Discourse::base_uri + "#{url_root}/#{clean_name}"
|
||
|
end
|
||
|
|
||
|
end
|