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
|