Sha256: 88020f19c3d2b226e111268ca84eeba3a2a2254662ee303e864e7b229cd1b2a9

Contents?: true

Size: 649 Bytes

Versions: 63

Compression:

Stored size: 649 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
        'image/jpeg'
      when /\.gif$/i
        'image/gif'
      when /\.png$/i
        'image/png'
      else
        'application/octet-stream'
      end
    end
  end
end

Version data entries

63 entries across 63 versions & 4 rubygems

Version Path
gemfury-0.12.0.rc1 lib/faraday/request/multipart_with_file.rb
gemfury-0.11.0 lib/faraday/request/multipart_with_file.rb
gemfury-0.11.0.rc1 lib/faraday/request/multipart_with_file.rb
gemfury-0.10.0 lib/faraday/request/multipart_with_file.rb
gemfury-0.10.0.rc1 lib/faraday/request/multipart_with_file.rb
gemfury-0.9.1 lib/faraday/request/multipart_with_file.rb
gemfury-0.9.0.rc1 lib/faraday/request/multipart_with_file.rb
gemfury-0.8.0 lib/faraday/request/multipart_with_file.rb
gemfury-0.8.0.rc1 lib/faraday/request/multipart_with_file.rb
gemfury-0.7.0 lib/faraday/request/multipart_with_file.rb
gemfury-0.6.0 lib/faraday/request/multipart_with_file.rb
gemfury-0.6.0.rc1 lib/faraday/request/multipart_with_file.rb
gemfury-0.5.0 lib/faraday/request/multipart_with_file.rb
gemfury-0.5.0.beta3 lib/faraday/request/multipart_with_file.rb
gemfury-0.5.0.beta1 lib/faraday/request/multipart_with_file.rb
gemfury-0.4.26 lib/faraday/request/multipart_with_file.rb
gemfury-0.4.26.beta1 lib/faraday/request/multipart_with_file.rb
gemfury-0.4.25 lib/faraday/request/multipart_with_file.rb
gemfury-0.4.24.beta5 lib/faraday/request/multipart_with_file.rb
gemfury-0.4.24.beta4 lib/faraday/request/multipart_with_file.rb