Module: Balloon::Uploader

Extended by:
ActiveSupport::Concern
Included in:
Base
Defined in:
lib/balloon/uploader.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#save_to_cache(up_file) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/balloon/uploader.rb', line 20

def save_to_cache(up_file)
  upload_data = {}
  uploader_file = up_file

  if up_file.is_a?(String) && up_file.include?("://")
    upload_data[:remote_url] = up_file
    uploader_file = down_url(up_file)
  end

  if up_file.is_a?(::ActionDispatch::Http::UploadedFile)
    upload_data[:original_filename] = up_file.original_filename
  end

  uploader_file_ext = Balloon::FileExtension.new(uploader_file)
  file_mime_type = uploader_file_ext.mime_type

  if self.respond_to?(:uploader_mimetype_white)
    if !uploader_mimetype_white.include?(file_mime_type)
      raise Balloon::DownloadError, I18n.translate(:"errors.messages.down_mime_error")
    end
  end

  if self.respond_to?(:uploader_mimetype_black)
    if !uploader_mimetype_black.include?(file_mime_type)
      raise Balloon::DownloadError, I18n.translate(:"errors.messages.down_mime_error")
    end
  end

  generate_cache_directory
  up_file = uploader_file_ext.save_to cache_path, permissions
  @cache_meta = image_processing up_file
  @meta = {
    width: @cache_meta[:width],
    height: @cache_meta[:height],
    size: @cache_meta[:size],
    mime_type: @cache_meta[:mime_type],
    extension: @cache_meta[:extension],
    upload_data: upload_data,
    data: upload_data.merge(@cache_meta[:data])
  }
end

#set_storage_engineObject



16
17
18
# File 'lib/balloon/uploader.rb', line 16

def set_storage_engine
  @storage_engine = eval(Balloon::Base::STORAGE_EGINE[store_storage.to_sym]).new(self) if !respond_to?(:@storage_engine)
end

#url(size_name = nil) ⇒ Object



62
# File 'lib/balloon/uploader.rb', line 62

def url(size_name = nil); end