Sha256: cabfb9ac006ff3b30cda40aac34a50e83bfcc25668733e0a4151cd1756c1ff5e

Contents?: true

Size: 623 Bytes

Versions: 8

Compression:

Stored size: 623 Bytes

Contents

require 'faraday'

# @api private
module Faraday
  class Request::Multipart < Faraday::Middleware
    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

    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
  end
end

Version data entries

8 entries across 8 versions & 4 rubygems

Version Path
sba-0.0.1 lib/faraday/multipart.rb
recalls-0.1 lib/faraday/multipart.rb
Recalls-0.1 lib/faraday/multipart.rb
open311-0.1.2 lib/faraday/multipart.rb
open311-0.1.1 lib/faraday/multipart.rb
open311-0.1.0 lib/faraday/multipart.rb
open311-0.0.1 lib/faraday/multipart.rb
open311-0.0.0 lib/faraday/multipart.rb