Sha256: c38868033647e62d0eea2214c2c5272ec5117bae18a995dfe623f0ba75243a84

Contents?: true

Size: 640 Bytes

Versions: 35

Compression:

Stored size: 640 Bytes

Contents

require 'faraday'

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

35 entries across 35 versions & 4 rubygems

Version Path
desk-1.2.0 lib/faraday/request/multipart_with_file.rb
desk-1.1.1 lib/faraday/request/multipart_with_file.rb
desk-1.1.0 lib/faraday/request/multipart_with_file.rb
desk-1.0.10 lib/faraday/request/multipart_with_file.rb
desk-1.0.9 lib/faraday/request/multipart_with_file.rb
desk-1.0.8 lib/faraday/request/multipart_with_file.rb
desk-1.0.7 lib/faraday/request/multipart_with_file.rb
desk-1.0.6 lib/faraday/request/multipart_with_file.rb
desk-1.0.5 lib/faraday/request/multipart_with_file.rb
desk-1.0.4 lib/faraday/request/multipart_with_file.rb
desk-1.0.3 lib/faraday/request/multipart_with_file.rb
desk-1.0.2 lib/faraday/request/multipart_with_file.rb
desk-1.0.1 lib/faraday/request/multipart_with_file.rb
desk-1.0.0 lib/faraday/request/multipart_with_file.rb
desk-0.3.3 lib/faraday/request/multipart_with_file.rb
desk-0.3.2 lib/faraday/request/multipart_with_file.rb
desk-0.3.1 lib/faraday/request/multipart_with_file.rb
desk-0.3.0 lib/faraday/request/multipart_with_file.rb
assistly-0.2.6 lib/faraday/request/multipart_with_file.rb
assistly-0.2.5 lib/faraday/request/multipart_with_file.rb