Sha256: a9ec24491a5ab3ecd2ec93278965da26f2933ea3cdf14cce4f6aee54ca8e3a12

Contents?: true

Size: 632 Bytes

Versions: 9

Compression:

Stored size: 632 Bytes

Contents

require 'faraday'

# @private
module Faraday
  # @private
  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

9 entries across 9 versions & 4 rubygems

Version Path
ruby-slideshare-0.1.3 lib/faraday/multipart.rb
ruby-slideshare-0.1.2 lib/faraday/multipart.rb
super-mega-slideshare-0.1.2 lib/faraday/multipart.rb
super-mega-slideshare-0.1.1 lib/faraday/multipart.rb
super-mega-slideshare-0.1.0 lib/faraday/multipart.rb
smoodit-0.0.2 lib/faraday/multipart.rb
smoodit-0.0.1 lib/faraday/multipart.rb
thounds-0.0.2 lib/faraday/multipart.rb
thounds-0.0.1 lib/faraday/multipart.rb