diff options
author | Earle Bunao & Neil Calabroso <earle.bunao@gmail.com & nmcalabroso@gmail.com> | 2014-05-23 16:22:00 +0800 |
---|---|---|
committer | erbunao <earle.bunao@gmail.com> | 2014-05-23 16:22:42 +0800 |
commit | 6a85cdf1627629ecaa762fa60a7abdbd092cc20a (patch) | |
tree | ada8c5565fa6e336b3074b4e606273029c473d0a /app/uploaders | |
parent | 696b9903f08011e37811dc8b8ff4f7da77201d13 (diff) | |
download | gitlab-ce-6a85cdf1627629ecaa762fa60a7abdbd092cc20a.tar.gz |
Implements drag and drop upload in creating issues
Diffstat (limited to 'app/uploaders')
-rw-r--r-- | app/uploaders/file_uploader.rb | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/app/uploaders/file_uploader.rb b/app/uploaders/file_uploader.rb new file mode 100644 index 00000000000..cbc9271ac14 --- /dev/null +++ b/app/uploaders/file_uploader.rb @@ -0,0 +1,41 @@ +# encoding: utf-8 +class FileUploader < CarrierWave::Uploader::Base + storage :file + + def initialize(base_dir, path = '', allowed_extensions = nil) + @base_dir = base_dir + @path = path + @allowed_extensions = allowed_extensions + end + + def base_dir + @base_dir + end + + def store_dir + File.join(@base_dir, @path) + end + + def cache_dir + File.join(@base_dir, 'tmp', @path) + end + + def extension_white_list + @allowed_extensions + end + + def store!(file) + file.original_filename = self.class.generate_filename(file) + super + end + + def self.generate_filename(file) + original_filename = File.basename(file.original_filename, '.*') + extension = File.extname(file.original_filename) + new_filename = Digest::MD5.hexdigest(original_filename) + extension + end + + def self.generate_dir + SecureRandom.hex(5) + end +end |