Sha256: 07285e87f929bbe7d0c3bba4c56d6665a2ebf826edd97cf1c60f6941d2d1bf45
Contents?: true
Size: 1.63 KB
Versions: 1
Compression:
Stored size: 1.63 KB
Contents
module CarrierWave module Downloader class RemoteFile attr_reader :file, :uri def initialize(file) case file when String @file = StringIO.new(file) when Net::HTTPResponse body = file.body raise CarrierWave::DownloadError, 'could not download file: No Content' if body.nil? @file = StringIO.new(body) @content_type = file.content_type @headers = file @uri = file.uri else @file = file @content_type = file.content_type @headers = file.meta @uri = file.base_uri end end def content_type @content_type || 'application/octet-stream' end def headers @headers || {} end def original_filename filename = filename_from_header || filename_from_uri mime_type = Marcel::TYPES[content_type] unless File.extname(filename).present? || mime_type.blank? extension = mime_type[0].first filename = "#{filename}.#{extension}" end filename end def respond_to?(*args) super || file.respond_to?(*args) end private def filename_from_header return nil unless headers['content-disposition'] match = headers['content-disposition'].match(/filename=(?:"([^"]+)"|([^";]+))/) return nil unless match match[1].presence || match[2].presence end def filename_from_uri CGI.unescape(File.basename(uri.path)) end def method_missing(*args, &block) file.send(*args, &block) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
carrierwave-3.0.0.beta | lib/carrierwave/downloader/remote_file.rb |