Skip to content

Commit

Permalink
Fix README example and missing require.
Browse files Browse the repository at this point in the history
  • Loading branch information
iMacTia committed Jan 4, 2022
1 parent ec81aae commit db04ec8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ only under these conditions:

Faraday contains a couple helper classes for multipart values:

* `Faraday::FilePart` wraps binary file data with a Content-Type. The file data can be specified with a String path to a
* `Faraday::Multipart::FilePart` wraps binary file data with a Content-Type. The file data can be specified with a String path to a
local file, or an IO object.
* `Faraday::ParamPart` wraps a String value with a Content-Type, and optionally a Content-ID.
* `Faraday::Multipart::ParamPart` wraps a String value with a Content-Type, and optionally a Content-ID.

## Installation

Expand Down Expand Up @@ -57,32 +57,32 @@ Payload can be a mix of POST data and multipart values.
payload = { string: 'value' }

# filename for this value is File.basename(__FILE__)
payload[:file] = Faraday::FilePart.new(__FILE__, 'text/x-ruby')
payload[:file] = Faraday::Multipart::FilePart.new(__FILE__, 'text/x-ruby')

# specify filename because IO object doesn't know it
payload[:file_with_name] = Faraday::FilePart.new(
payload[:file_with_name] = Faraday::Multipart::FilePart.new(
File.open(__FILE__),
'text/x-ruby',
File.basename(__FILE__)
)

# Sets a custom Content-Disposition:
# nil filename still defaults to File.basename(__FILE__)
payload[:file_with_header] = Faraday::FilePart.new(
payload[:file_with_header] = Faraday::Multipart::FilePart.new(
__FILE__,
'text/x-ruby',
nil,
'Content-Disposition' => 'form-data; foo=1'
)

# Upload raw json with content type
payload[:raw_data] = Faraday::ParamPart.new(
payload[:raw_data] = Faraday::Multipart::ParamPart.new(
{ a: 1 }.to_json,
'application/json'
)

# optionally sets Content-ID too
payload[:raw_with_id] = Faraday::ParamPart.new(
payload[:raw_with_id] = Faraday::Multipart::ParamPart.new(
{ a: 1 }.to_json,
'application/json',
'foo-123'
Expand Down
2 changes: 2 additions & 0 deletions lib/faraday/multipart/middleware.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'securerandom'

module Faraday
module Multipart
# Middleware for supporting multi-part requests.
Expand Down

0 comments on commit db04ec8

Please sign in to comment.