class Faraday::Request::MultipartWithFile

@private

Public Instance Methods

call(env) click to toggle source
# File lib/faraday/request/multipart_with_file.rb, line 7
def call(env)
  if env[:body].is_a?(Hash)
    env[:body].each do |key, value|
      if value.is_a?(File)
        env[:body][key] = Faraday::UploadIO.new(value, mime_type(value), value.path)
      end
    end
  end

  @app.call(env)
end

Private Instance Methods

mime_type(file) click to toggle source
# File lib/faraday/request/multipart_with_file.rb, line 21
def mime_type(file)
  case file.path
    when /\.jpe?g/i then 'image/jpeg'
    when /\.gif$/i then 'image/gif'
    when /\.png$/i then 'image/png'
    else 'application/octet-stream'
  end
end