A summary of data about the Ruby ecosystem.

https://github.com/socketry/multipart-post

Adds multipart POST capability to net/http
https://github.com/socketry/multipart-post

Keywords from Contributors

rubygems activerecord activejob mvc rspec rack sinatra ruby-gem pagination oauth2

Last synced: about 1 hour ago
JSON representation

Repository metadata

Adds multipart POST capability to net/http

readme.md

Multipart::Post

Adds a streamy multipart form post capability to Net::HTTP. Also supports other
methods besides POST.

Development Status

Features/Problems

  • Appears to actually work. A good feature to have.
  • Encapsulates posting of file/binary parts and name/value parameter parts, similar to
    most browsers' file upload forms.
  • Provides an UploadIO helper class to prepare IO objects for inclusion in the params
    hash of the multipart post object.

Installation

bundle add multipart-post

Usage

require 'net/http/post/multipart'

url = URI.parse('http://www.example.com/upload')
File.open("./image.jpg") do |jpg|
  req = Net::HTTP::Post::Multipart.new url.path,
    "file" => UploadIO.new(jpg, "image/jpeg", "image.jpg")
  res = Net::HTTP.start(url.host, url.port) do |http|
    http.request(req)
  end
end

To post multiple files or attachments, simply include multiple parameters with
UploadIO values:

require 'net/http/post/multipart'

url = URI.parse('http://www.example.com/upload')
req = Net::HTTP::Post::Multipart.new url.path,
  "file1" => UploadIO.new(File.new("./image.jpg"), "image/jpeg", "image.jpg"),
  "file2" => UploadIO.new(File.new("./image2.jpg"), "image/jpeg", "image2.jpg")
res = Net::HTTP.start(url.host, url.port) do |http|
  http.request(req)
end

To post files with other normal, non-file params such as input values, you need to pass hashes to the Multipart.new method.

In Rails 4 for example:

def model_params
  require_params = params.require(:model).permit(:param_one, :param_two, :param_three, :avatar)
  require_params[:avatar] = model_params[:avatar].present? ? UploadIO.new(model_params[:avatar].tempfile, model_params[:avatar].content_type, model_params[:avatar].original_filename) : nil
  require_params
end

require 'net/http/post/multipart'

url = URI.parse('http://www.example.com/upload')
Net::HTTP.start(url.host, url.port) do |http|
  req = Net::HTTP::Post::Multipart.new(url, model_params)
  key = "authorization_key"
  req.add_field("Authorization", key) #add to Headers
  http.use_ssl = (url.scheme == "https")
  http.request(req)
end

Or in plain ruby:

def params(file)
  params = { "description" => "A nice picture!" }
  params[:datei] = UploadIO.new(file, "image/jpeg", "image.jpg")
  params
end

url = URI.parse('http://www.example.com/upload')
File.open("./image.jpg") do |file|
  req = Net::HTTP::Post::Multipart.new(url.path, params(file))
  res = Net::HTTP.start(url.host, url.port) do |http|
    return http.request(req).body
  end
end

Parts Headers

By default, all individual parts will include the header Content-Disposition as well as Content-Length, Content-Transfer-Encoding and Content-Type for the File Parts.

You may optionally configure the headers Content-Type and Content-ID for both ParamPart and FilePart by passing in a parts header.

For example:

url = URI.parse('http://www.example.com/upload')

params = {
  "file_metadata_01" => { "description" => "A nice picture!" },
  "file_content_01"  => UploadIO.new(file, "image/jpeg", "image.jpg")
}

headers = {
  'parts': {
    'file_metadata_01': {
      'Content-Type' => "application/json"
      }
    }
  }

req = Net::HTTP::Post::Multipart.new(uri, params, headers)

This would configure the file_metadata_01 part to include Content-Type

Content-Disposition: form-data; name="file_metadata_01"
Content-Type: application/json
  {
    "description" => "A nice picture!" 
  }

Custom Parts Headers

For FileParts only.

You can include any number of custom parts headers in addition to Content-Type and Content-ID.

headers = {
  'parts': {
    'file_metadata_01': {
      'Content-Type' => "application/json",
      'My-Custom-Header' => "Yo Yo!"
    }
  }
}

Debugging

You can debug requests and responses (e.g. status codes) for all requests by adding the following code:

http = Net::HTTP.new(uri.host, uri.port)
http.set_debug_output($stdout)

Versioning

This library aims to adhere to Semantic Versioning 2.0.0.
Violations of this scheme should be reported as bugs. Specifically,
if a minor or patch version is released that breaks backward
compatibility, a new version should be immediately released that
restores compatibility. Breaking changes to the public API will
only be introduced with new major versions.

As a result of this policy, you can (and should) specify a
dependency on this gem using the Pessimistic Version Constraint with two digits of precision.

For example:

spec.add_dependency 'multipart-post', '~> 2.1'

Owner metadata


GitHub Events

Total
Last Year

Committers metadata

Last synced: 1 day ago

Total Commits: 168
Total Committers: 38
Avg Commits per committer: 4.421
Development Distribution Score (DDS): 0.726

Commits in past year: 0
Committers in past year: 0
Avg Commits per committer in past year: 0.0
Development Distribution Score (DDS) in past year: 0.0

Name Email Commits
Nick Sieger n****k@n****m 46
Samuel Williams s****s@o****z 41
Olle Jonsson o****n@g****m 15
McClain Looney m@l****m 9
Lewis Cowles l****b@c****k 8
Patrick Davey p****y@g****m 5
Gustav Ernberg g****b@m****e 4
Steven Davidovitz s****z@z****m 3
Tohru Hashimoto s****o@g****m 2
Jason York j****k@g****m 2
Jagtesh Chadha j****h@g****m 2
Ethan Turkeltaub e****b@g****m 2
Alex Koppel a****t@a****m 2
hexfet j****3@y****m 2
Vincent Pellé v****p@w****m 2
Socrates Vicente s****e@n****m 1
Gerrit Riessen g****n@g****m 1
David Moles d****s@u****u 1
Christine Yen c****n@c****m 1
Tim Barkley T****y@g****m 1
Takuya Noguchi t****h@g****m 1
Steffen Grunwald s****d@g****m 1
Peter Goldstein p****n@g****m 1
Mislav Marohnić m****c@g****m 1
Matt Colyer m****t@c****e 1
Masato Nakamura m****5@g****m 1
Luke Redpath l****e@l****k 1
Lonre Wang l****e 1
Leo Cassarani l****i@m****m 1
Lachlan Priest l****t@g****m 1
and 8 more...

Committer domains:


Issue and Pull Request metadata

Last synced: 2 days ago

Total issues: 37
Total pull requests: 68
Average time to close issues: over 2 years
Average time to close pull requests: 3 months
Total issue authors: 36
Total pull request authors: 38
Average comments per issue: 3.97
Average comments per pull request: 1.32
Merged pull request: 56
Bot issues: 0
Bot pull requests: 1

Past year issues: 1
Past year pull requests: 1
Past year average time to close issues: N/A
Past year average time to close pull requests: N/A
Past year issue authors: 1
Past year pull request authors: 1
Past year average comments per issue: 1.0
Past year average comments per pull request: 0.0
Past year merged pull request: 0
Past year bot issues: 0
Past year bot pull requests: 1

More stats: https://issues.ecosyste.ms/repositories/lookup?url=https://github.com/socketry/multipart-post

Top Issue Authors

  • olleolleolle (2)
  • arsduo (1)
  • koshigoe (1)
  • ts-3156 (1)
  • gavinkou (1)
  • Domon (1)
  • ajinkya-bhosale (1)
  • huacnlee (1)
  • joankaradimov (1)
  • edgedalmacio (1)
  • jrochkind (1)
  • jonkelleyatrackspace (1)
  • xiconet (1)
  • ioquatix (1)
  • jimtsay (1)

Top Pull Request Authors

  • ioquatix (15)
  • olleolleolle (14)
  • Lewiscowles1986 (4)
  • m-nakamura145 (2)
  • steffeng (2)
  • patrickdavey (2)
  • dependabot[bot] (2)
  • captainbeardo (1)
  • mislav (1)
  • jspanjers (1)
  • dmolesUC (1)
  • lukeredpath (1)
  • Phitherek (1)
  • jordimassaguerpla (1)
  • jaimeiniesta (1)

Top Issue Labels

Top Pull Request Labels

  • dependencies (2)

Package metadata

gem.coop: multipart-post

A multipart form post accessory for Net::HTTP.

  • Homepage: https://github.com/socketry/multipart-post
  • Documentation: http://www.rubydoc.info/gems/multipart-post/
  • Licenses: MIT
  • Latest release: 2.4.1 (published almost 2 years ago)
  • Last Synced: 2026-03-02T01:01:56.090Z (2 days ago)
  • Versions: 19
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 850,967,831 Total
  • Docker Downloads: 1,356,977,955
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Downloads: 0.016%
    • Average: 0.022%
    • Docker downloads count: 0.07%
  • Maintainers (1)
rubygems.org: multipart-post

A multipart form post accessory for Net::HTTP.

  • Homepage: https://github.com/socketry/multipart-post
  • Documentation: http://www.rubydoc.info/gems/multipart-post/
  • Licenses: MIT
  • Latest release: 2.4.1 (published almost 2 years ago)
  • Last Synced: 2026-03-02T04:32:37.806Z (2 days ago)
  • Versions: 19
  • Dependent Packages: 275
  • Dependent Repositories: 470,132
  • Downloads: 851,002,054 Total
  • Docker Downloads: 1,356,977,955
  • Rankings:
    • Downloads: 0.017%
    • Dependent repos count: 0.035%
    • Docker downloads count: 0.09%
    • Dependent packages count: 0.153%
    • Average: 1.12%
    • Forks count: 3.12%
    • Stargazers count: 3.303%
  • Maintainers (1)
proxy.golang.org: github.com/socketry/multipart-post

conda-forge.org: rb-multipart-post

  • Homepage: https://rubygems.org/gems/multipart-post
  • Licenses: MIT
  • Latest release: 2.1.1 (published over 6 years ago)
  • Last Synced: 2026-03-01T12:29:46.048Z (2 days ago)
  • Versions: 1
  • Dependent Packages: 1
  • Dependent Repositories: 1
  • Rankings:
    • Forks count: 21.698%
    • Stargazers count: 22.875%
    • Dependent repos count: 24.377%
    • Average: 24.482%
    • Dependent packages count: 28.978%

Dependencies

gems.rb rubygems
  • bake >= 0
  • bake-gem >= 0
  • bake-modernize >= 0
multipart-post.gemspec rubygems
  • bundler >= 0 development
  • rspec ~> 3.4 development
.github/workflows/coverage.yaml actions
  • actions/checkout v3 composite
  • actions/download-artifact v3 composite
  • actions/upload-artifact v2 composite
  • ruby/setup-ruby v1 composite
.github/workflows/test-external.yaml actions
  • actions/checkout v3 composite
  • ruby/setup-ruby v1 composite
.github/workflows/test.yaml actions
  • actions/checkout v3 composite
  • ruby/setup-ruby v1 composite
.github/workflows/documentation.yaml actions
  • actions/checkout v4 composite
  • actions/deploy-pages v3 composite
  • actions/upload-pages-artifact v2 composite
  • ruby/setup-ruby v1 composite

Score: 31.563204819732753