https://github.com/lostisland/faraday-multipart
Perform multipart-post requests using Faraday.
https://github.com/lostisland/faraday-multipart
Keywords from Contributors
feature-flag
Last synced: 13 minutes ago
JSON representation
Repository metadata
Perform multipart-post requests using Faraday.
- Host: GitHub
- URL: https://github.com/lostisland/faraday-multipart
- Owner: lostisland
- License: mit
- Created: 2022-01-02T20:50:06.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2025-12-25T16:42:54.000Z (2 months ago)
- Last Synced: 2026-02-20T13:59:46.181Z (11 days ago)
- Language: Ruby
- Size: 41 KB
- Stars: 22
- Watchers: 2
- Forks: 8
- Open Issues: 2
- Releases: 9
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
README.md
Faraday Multipart
The Multipart middleware converts a Faraday::Request#body Hash of key/value pairs into a multipart form request, but
only under these conditions:
- The request's Content-Type is "multipart/form-data"
- Content-Type is unspecified, AND one of the values in the Body responds to
#content_type.
Faraday contains a couple helper classes for multipart values:
Faraday::Multipart::FilePartwraps 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::Multipart::ParamPartwraps a String value with a Content-Type, and optionally a Content-ID.
Installation
Add this line to your application's Gemfile:
gem 'faraday-multipart'
And then execute:
bundle install
Or install it yourself as:
gem install faraday-multipart
Usage
First of all, you'll need to add the multipart middleware to your Faraday connection:
require 'faraday'
require 'faraday/multipart'
conn = Faraday.new(...) do |f|
f.request :multipart, **options
# ...
end
If you need to specify a different content type for the multipart
request,
you can do so by providing the content_type option but it must start with
multipart/
otherwise it will default to multipart/form-data:
conn = Faraday.new(...) do |f|
f.request :multipart, content_type: 'multipart/mixed'
# ...
end
Payload can be a mix of POST data and multipart values.
# regular POST form value
payload = { string: 'value' }
# filename for this value is File.basename(__FILE__)
payload[:file] = Faraday::Multipart::FilePart.new(__FILE__, 'text/x-ruby')
# specify filename because IO object doesn't know it
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::Multipart::FilePart.new(
__FILE__,
'text/x-ruby',
nil,
'Content-Disposition' => 'form-data; foo=1'
)
# Upload raw json with content type
payload[:raw_data] = Faraday::Multipart::ParamPart.new(
{ a: 1 }.to_json,
'application/json'
)
# optionally sets Content-ID too
payload[:raw_with_id] = Faraday::Multipart::ParamPart.new(
{ a: 1 }.to_json,
'application/json',
'foo-123'
)
conn.post('/', payload)
Sending an array of documents
Sometimes, the server you're calling will expect an array of documents or other values for the same key.
The multipart middleware will automatically handle this scenario for you:
payload = {
files: [
Faraday::Multipart::FilePart.new(__FILE__, 'text/x-ruby'),
Faraday::Multipart::FilePart.new(__FILE__, 'text/x-pdf')
],
url: [
'http://mydomain.com/callback1',
'http://mydomain.com/callback2'
]
}
conn.post(url, payload)
#=> POST url[]=http://mydomain.com/callback1&url[]=http://mydomain.com/callback2
#=> and includes both files in the request under the `files[]` name
However, by default these will be sent with files[] key and the URLs with url[], similarly to arrays in URL parameters.
Some servers (e.g. Mailgun) expect each document to have the same parameter key instead.
You can instruct the multipart middleware to do so by providing the flat_encode option:
require 'faraday'
require 'faraday/multipart'
conn = Faraday.new(...) do |f|
f.request :multipart, flat_encode: true
# ...
end
payload = ... # see example above
conn.post(url, payload)
#=> POST url=http://mydomain.com/callback1&url=http://mydomain.com/callback2
#=> and includes both files in the request under the `files` name
This works for both UploadIO and normal parameters alike.
Development
After checking out the repo, run bin/setup to install dependencies.
Then, run bin/test to run the tests.
To install this gem onto your local machine, run rake build.
Releasing a new version
To release a new version, make a commit with a message such as "Bumped to 0.0.2", and change the Unreleased heading in CHANGELOG.md to a heading like "0.0.2 (2022-01-01)", and then use GitHub Releases to author a release. A GitHub Actions workflow then publishes a new gem to RubyGems.org.
Contributing
Bug reports and pull requests are welcome on GitHub.
License
The gem is available as open source under the terms of the MIT License.
Owner metadata
- Name: lostisland
- Login: lostisland
- Email:
- Kind: organization
- Description:
- Website:
- Location:
- Twitter:
- Company:
- Icon url: https://avatars.githubusercontent.com/u/2613464?v=4
- Repositories: 22
- Last ynced at: 2024-03-25T19:32:01.094Z
- Profile URL: https://github.com/lostisland
GitHub Events
Total
- Release event: 4
- Delete event: 2
- Pull request event: 5
- Fork event: 3
- Issues event: 8
- Watch event: 4
- Issue comment event: 15
- Push event: 6
- Pull request review comment event: 5
- Pull request review event: 6
- Create event: 4
Last Year
- Release event: 2
- Delete event: 1
- Pull request event: 3
- Fork event: 2
- Issues event: 6
- Watch event: 3
- Issue comment event: 4
- Push event: 4
- Pull request review event: 1
- Create event: 2
Committers metadata
Last synced: 1 day ago
Total Commits: 30
Total Committers: 6
Avg Commits per committer: 5.0
Development Distribution Score (DDS): 0.533
Commits in past year: 7
Committers in past year: 4
Avg Commits per committer in past year: 1.75
Development Distribution Score (DDS) in past year: 0.429
| Name | Commits | |
|---|---|---|
| Matt | i****a | 14 |
| Olle Jonsson | o****n@g****m | 12 |
| Taketo Takashima | t****3@g****m | 1 |
| Juna Ootoovak | 1****b | 1 |
| João Duarte | j****d | 1 |
| Eugene Smentyna | d****a@g****m | 1 |
Issue and Pull Request metadata
Last synced: 2 months ago
Total issues: 10
Total pull requests: 14
Average time to close issues: 12 days
Average time to close pull requests: 4 days
Total issue authors: 9
Total pull request authors: 6
Average comments per issue: 2.2
Average comments per pull request: 1.93
Merged pull request: 13
Bot issues: 0
Bot pull requests: 0
Past year issues: 4
Past year pull requests: 4
Past year average time to close issues: 2 days
Past year average time to close pull requests: 2 days
Past year issue authors: 3
Past year pull request authors: 3
Past year average comments per issue: 1.0
Past year average comments per pull request: 0.75
Past year merged pull request: 3
Past year bot issues: 0
Past year bot pull requests: 0
Top Issue Authors
- zedalaye (2)
- olleolleolle (1)
- kashiftufail (1)
- spidzio (1)
- diogolsq (1)
- pbourdet (1)
- triplef (1)
- kwent (1)
- richardrails (1)
Top Pull Request Authors
- olleolleolle (6)
- juna-nb (2)
- iMacTia (2)
- djsmentya (2)
- jsvd (1)
- taketo1113 (1)
Top Issue Labels
Top Pull Request Labels
Package metadata
- Total packages: 7
-
Total downloads:
- rubygems: 655,538,915 total
- Total docker downloads: 1,876,994,042
- Total dependent packages: 147 (may contain duplicates)
- Total dependent repositories: 11,695 (may contain duplicates)
- Total versions: 28
- Total maintainers: 1
gem.coop: faraday-multipart
Perform multipart-post requests using Faraday.
- Homepage: https://github.com/lostisland/faraday-multipart
- Documentation: http://www.rubydoc.info/gems/faraday-multipart/
- Licenses: MIT
- Latest release: 1.2.0 (published 2 months ago)
- Last Synced: 2026-03-02T07:02:08.418Z (1 day ago)
- Versions: 8
- Dependent Packages: 0
- Dependent Repositories: 0
- Downloads: 327,867,780 Total
- Docker Downloads: 938,497,021
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Average: 0.028%
- Downloads: 0.083%
- Maintainers (1)
rubygems.org: faraday-multipart
Perform multipart-post requests using Faraday.
- Homepage: https://github.com/lostisland/faraday-multipart
- Documentation: http://www.rubydoc.info/gems/faraday-multipart/
- Licenses: MIT
- Latest release: 1.2.0 (published 2 months ago)
- Last Synced: 2026-02-28T16:00:39.882Z (3 days ago)
- Versions: 8
- Dependent Packages: 147
- Dependent Repositories: 11,695
- Downloads: 327,671,135 Total
- Docker Downloads: 938,497,021
-
Rankings:
- Docker downloads count: 0.122%
- Downloads: 0.123%
- Dependent packages count: 0.283%
- Dependent repos count: 0.317%
- Average: 4.568%
- Stargazers count: 13.201%
- Forks count: 13.364%
- Maintainers (1)
proxy.golang.org: github.com/lostisland/faraday-multipart
- Homepage:
- Documentation: https://pkg.go.dev/github.com/lostisland/faraday-multipart#section-documentation
- Licenses: mit
- Latest release: v1.2.0 (published 2 months ago)
- Last Synced: 2026-02-27T20:43:13.372Z (4 days ago)
- Versions: 8
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Forks count: 8.829%
- Stargazers count: 8.869%
- Average: 9.519%
- Dependent packages count: 9.576%
- Dependent repos count: 10.802%
ubuntu-23.10: ruby-faraday-multipart
- Homepage: https://github.com/lostisland/faraday-multipart
- Licenses:
- Latest release: 1.0.4-1 (published 18 days ago)
- Last Synced: 2026-02-13T18:19:41.144Z (18 days ago)
- Versions: 1
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Average: 100%
debian-13: ruby-faraday-multipart
- Homepage: https://github.com/lostisland/faraday-multipart
- Documentation: https://packages.debian.org/trixie/ruby-faraday-multipart
- Licenses:
- Latest release: 1.0.4-2 (published 19 days ago)
- Last Synced: 2026-02-13T13:15:12.218Z (18 days ago)
- Versions: 1
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Average: 100%
Dependencies
- actions/checkout v3 composite
- ruby/setup-ruby v1 composite
- actions/checkout v3 composite
- actions/setup-ruby v1 composite
- dawidd6/action-publish-gem v1 composite
- bundler ~> 2.0 development
- faraday >= 1.0 development
- multipart-parser >= 0 development
- rake ~> 13.0 development
- rspec ~> 3.0 development
- rubocop ~> 1.12.0 development
- rubocop-packaging ~> 0.5.0 development
- rubocop-performance ~> 1.0 development
- rubocop-rspec ~> 2.0 development
- simplecov ~> 0.18.0 development
- multipart-post ~> 2.0
Score: 26.622304405835028