multipart-post 2.1.1 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/composite_io.rb +2 -108
- data/lib/multipart/post/composite_read_io.rb +78 -0
- data/lib/multipart/post/multipartable.rb +75 -0
- data/lib/multipart/post/parts.rb +152 -0
- data/lib/multipart/post/upload_io.rb +81 -0
- data/lib/multipart/post/version.rb +27 -0
- data/lib/multipart/post.rb +24 -0
- data/lib/multipart_post.rb +3 -9
- data/lib/multipartable.rb +2 -48
- data/lib/net/http/post/multipart.rb +25 -12
- data/lib/parts.rb +2 -126
- data.tar.gz.sig +1 -0
- metadata +90 -52
- metadata.gz.sig +2 -0
- data/.gitignore +0 -6
- data/.rspec +0 -5
- data/.travis.yml +0 -20
- data/.yardopts +0 -6
- data/Gemfile +0 -6
- data/History.txt +0 -64
- data/LICENSE +0 -21
- data/Manifest.txt +0 -9
- data/README.md +0 -127
- data/Rakefile +0 -6
- data/multipart-post.gemspec +0 -23
- data/spec/composite_io_spec.rb +0 -138
- data/spec/multibyte.txt +0 -1
- data/spec/net/http/post/multipart_spec.rb +0 -123
- data/spec/parts_spec.rb +0 -102
- data/spec/spec_helper.rb +0 -29
data/lib/parts.rb
CHANGED
@@ -1,126 +1,2 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
# See the file README.txt included with the distribution for
|
4
|
-
# software license details.
|
5
|
-
#++
|
6
|
-
|
7
|
-
module Parts
|
8
|
-
module Part
|
9
|
-
def self.new(boundary, name, value, headers = {})
|
10
|
-
headers ||= {} # avoid nil values
|
11
|
-
if file?(value)
|
12
|
-
FilePart.new(boundary, name, value, headers)
|
13
|
-
else
|
14
|
-
ParamPart.new(boundary, name, value, headers)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.file?(value)
|
19
|
-
value.respond_to?(:content_type) && value.respond_to?(:original_filename)
|
20
|
-
end
|
21
|
-
|
22
|
-
def length
|
23
|
-
@part.length
|
24
|
-
end
|
25
|
-
|
26
|
-
def to_io
|
27
|
-
@io
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
# Represents a parametric part to be filled with given value.
|
32
|
-
class ParamPart
|
33
|
-
include Part
|
34
|
-
|
35
|
-
# @param boundary [String]
|
36
|
-
# @param name [#to_s]
|
37
|
-
# @param value [String]
|
38
|
-
# @param headers [Hash] Content-Type is used, if present.
|
39
|
-
def initialize(boundary, name, value, headers = {})
|
40
|
-
@part = build_part(boundary, name, value, headers)
|
41
|
-
@io = StringIO.new(@part)
|
42
|
-
end
|
43
|
-
|
44
|
-
def length
|
45
|
-
@part.bytesize
|
46
|
-
end
|
47
|
-
|
48
|
-
# @param boundary [String]
|
49
|
-
# @param name [#to_s]
|
50
|
-
# @param value [String]
|
51
|
-
# @param headers [Hash] Content-Type is used, if present.
|
52
|
-
def build_part(boundary, name, value, headers = {})
|
53
|
-
part = ''
|
54
|
-
part << "--#{boundary}\r\n"
|
55
|
-
part << "Content-Disposition: form-data; name=\"#{name.to_s}\"\r\n"
|
56
|
-
part << "Content-Type: #{headers["Content-Type"]}\r\n" if headers["Content-Type"]
|
57
|
-
part << "\r\n"
|
58
|
-
part << "#{value}\r\n"
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
# Represents a part to be filled from file IO.
|
63
|
-
class FilePart
|
64
|
-
include Part
|
65
|
-
|
66
|
-
attr_reader :length
|
67
|
-
|
68
|
-
# @param boundary [String]
|
69
|
-
# @param name [#to_s]
|
70
|
-
# @param io [IO]
|
71
|
-
# @param headers [Hash]
|
72
|
-
def initialize(boundary, name, io, headers = {})
|
73
|
-
file_length = io.respond_to?(:length) ? io.length : File.size(io.local_path)
|
74
|
-
@head = build_head(boundary, name, io.original_filename, io.content_type, file_length,
|
75
|
-
io.respond_to?(:opts) ? io.opts.merge(headers) : headers)
|
76
|
-
@foot = "\r\n"
|
77
|
-
@length = @head.bytesize + file_length + @foot.length
|
78
|
-
@io = CompositeReadIO.new(StringIO.new(@head), io, StringIO.new(@foot))
|
79
|
-
end
|
80
|
-
|
81
|
-
# @param boundary [String]
|
82
|
-
# @param name [#to_s]
|
83
|
-
# @param filename [String]
|
84
|
-
# @param type [String]
|
85
|
-
# @param content_len [Integer]
|
86
|
-
# @param opts [Hash]
|
87
|
-
def build_head(boundary, name, filename, type, content_len, opts = {})
|
88
|
-
opts = opts.clone
|
89
|
-
|
90
|
-
trans_encoding = opts.delete("Content-Transfer-Encoding") || "binary"
|
91
|
-
content_disposition = opts.delete("Content-Disposition") || "form-data"
|
92
|
-
|
93
|
-
part = ''
|
94
|
-
part << "--#{boundary}\r\n"
|
95
|
-
part << "Content-Disposition: #{content_disposition}; name=\"#{name.to_s}\"; filename=\"#{filename}\"\r\n"
|
96
|
-
part << "Content-Length: #{content_len}\r\n"
|
97
|
-
if content_id = opts.delete("Content-ID")
|
98
|
-
part << "Content-ID: #{content_id}\r\n"
|
99
|
-
end
|
100
|
-
|
101
|
-
if opts["Content-Type"] != nil
|
102
|
-
part << "Content-Type: " + opts["Content-Type"] + "\r\n"
|
103
|
-
else
|
104
|
-
part << "Content-Type: #{type}\r\n"
|
105
|
-
end
|
106
|
-
|
107
|
-
part << "Content-Transfer-Encoding: #{trans_encoding}\r\n"
|
108
|
-
|
109
|
-
opts.each do |k, v|
|
110
|
-
part << "#{k}: #{v}\r\n"
|
111
|
-
end
|
112
|
-
|
113
|
-
part << "\r\n"
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
# Represents the epilogue or closing boundary.
|
118
|
-
class EpiloguePart
|
119
|
-
include Part
|
120
|
-
|
121
|
-
def initialize(boundary)
|
122
|
-
@part = "--#{boundary}--\r\n"
|
123
|
-
@io = StringIO.new(@part)
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|
1
|
+
warn "Top level ::Parts is deprecated, require 'multipart/post' and use `Multipart::Post::Parts` instead!"
|
2
|
+
require_relative 'multipart/post'
|
data.tar.gz.sig
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
+�s\�H;�������<4ԏ<�,��X}Ȑv�Z:�'�܋��Љpޡ �?�L��WN"r�� �td‟�q��1�`��?�+e$�l�.�{�]�FwTY#��s��i衦PirD�!�������m��
|
metadata
CHANGED
@@ -1,15 +1,77 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: multipart-post
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Sieger
|
8
8
|
- Samuel Williams
|
9
|
-
|
9
|
+
- Olle Jonsson
|
10
|
+
- McClain Looney
|
11
|
+
- Lewis Cowles
|
12
|
+
- Gustav Ernberg
|
13
|
+
- Patrick Davey
|
14
|
+
- Steven Davidovitz
|
15
|
+
- Alex Koppel
|
16
|
+
- Ethan Turkeltaub
|
17
|
+
- Jagtesh Chadha
|
18
|
+
- Jason York
|
19
|
+
- Nick
|
20
|
+
- VincWebwag
|
21
|
+
- hasimo
|
22
|
+
- hexfet
|
23
|
+
- Christine Yen
|
24
|
+
- David Moles
|
25
|
+
- Eric Hutzelman
|
26
|
+
- Feuda Nan
|
27
|
+
- Gerrit Riessen
|
28
|
+
- Jan Piotrowski
|
29
|
+
- Jan-Joost Spanjers
|
30
|
+
- Jason Moore
|
31
|
+
- Jeff Hodges
|
32
|
+
- Johannes Wagener
|
33
|
+
- Jordi Massaguer Pla
|
34
|
+
- Lachlan Priest
|
35
|
+
- Leo Cassarani
|
36
|
+
- Lonre Wang
|
37
|
+
- Luke Redpath
|
38
|
+
- Matt Colyer
|
39
|
+
- Mislav Marohnić
|
40
|
+
- Socrates Vicente
|
41
|
+
- Steffen Grunwald
|
42
|
+
- Tim Barkley
|
43
|
+
autorequire:
|
10
44
|
bindir: bin
|
11
|
-
cert_chain:
|
12
|
-
|
45
|
+
cert_chain:
|
46
|
+
- |
|
47
|
+
-----BEGIN CERTIFICATE-----
|
48
|
+
MIIEhDCCAuygAwIBAgIBATANBgkqhkiG9w0BAQsFADA3MTUwMwYDVQQDDCxzYW11
|
49
|
+
ZWwud2lsbGlhbXMvREM9b3Jpb250cmFuc2Zlci9EQz1jby9EQz1uejAeFw0yMTA4
|
50
|
+
MTYwNjMzNDRaFw0yMjA4MTYwNjMzNDRaMDcxNTAzBgNVBAMMLHNhbXVlbC53aWxs
|
51
|
+
aWFtcy9EQz1vcmlvbnRyYW5zZmVyL0RDPWNvL0RDPW56MIIBojANBgkqhkiG9w0B
|
52
|
+
AQEFAAOCAY8AMIIBigKCAYEAyXLSS/cw+fXJ5e7hi+U/TeChPWeYdwJojDsFY1xr
|
53
|
+
xvtqbTTL8gbLHz5LW3QD2nfwCv3qTlw0qI3Ie7a9VMJMbSvgVEGEfQirqIgJXWMj
|
54
|
+
eNMDgKsMJtC7u/43abRKx7TCURW3iWyR19NRngsJJmaR51yGGGm2Kfsr+JtKKLtL
|
55
|
+
L188Wm3f13KAx7QJU8qyuBnj1/gWem076hzdA7xi1DbrZrch9GCRz62xymJlrJHn
|
56
|
+
9iZEZ7AxrS7vokhMlzSr/XMUihx/8aFKtk+tMLClqxZSmBWIErWdicCGTULXCBNb
|
57
|
+
E/mljo4zEVKhlTWpJklMIhr55ZRrSarKFuW7en0+tpJrfsYiAmXMJNi4XAYJH7uL
|
58
|
+
rgJuJwSaa/dMz+VmUoo7VKtSfCoOI+6v5/z0sK3oT6sG6ZwyI47DBq2XqNC6tnAj
|
59
|
+
w+XmCywiTQrFzMMAvcA7rPI4F0nU1rZId51rOvvfxaONp+wgTi4P8owZLw0/j0m4
|
60
|
+
8C20DYi6EYx4AHDXiLpElWh3AgMBAAGjgZowgZcwCQYDVR0TBAIwADALBgNVHQ8E
|
61
|
+
BAMCBLAwHQYDVR0OBBYEFB6ZaeWKxQjGTI+pmz7cKRmMIywwMC4GA1UdEQQnMCWB
|
62
|
+
I3NhbXVlbC53aWxsaWFtc0BvcmlvbnRyYW5zZmVyLmNvLm56MC4GA1UdEgQnMCWB
|
63
|
+
I3NhbXVlbC53aWxsaWFtc0BvcmlvbnRyYW5zZmVyLmNvLm56MA0GCSqGSIb3DQEB
|
64
|
+
CwUAA4IBgQBVoM+pu3dpdUhZM1w051iw5GfiqclAr1Psypf16Tiod/ho//4oAu6T
|
65
|
+
9fj3DPX/acWV9P/FScvqo4Qgv6g4VWO5ZU7z2JmPoTXZtYMunRAmQPFL/gSUc6aK
|
66
|
+
vszMHIyhtyzRc6DnfW2AiVOjMBjaYv8xXZc9bduniRVPrLR4J7ozmGLh4o4uJp7w
|
67
|
+
x9KCFaR8Lvn/r0oJWJOqb/DMAYI83YeN2Dlt3jpwrsmsONrtC5S3gOUle5afSGos
|
68
|
+
bYt5ocnEpKSomR9ZtnCGljds/aeO1Xgpn2r9HHcjwnH346iNrnHmMlC7BtHUFPDg
|
69
|
+
Ts92S47PTOXzwPBDsrFiq3VLbRjHSwf8rpqybQBH9MfzxGGxTaETQYOd6b4e4Ag6
|
70
|
+
y92abGna0bmIEb4+Tx9rQ10Uijh1POzvr/VTH4bbIPy9FbKrRsIQ24qDbNJRtOpE
|
71
|
+
RAOsIl+HOBTb252nx1kIRN5hqQx272AJCbCjKx8egcUQKffFVVCI0nye09v5CK+a
|
72
|
+
HiLJ8VOFx6w=
|
73
|
+
-----END CERTIFICATE-----
|
74
|
+
date: 2022-06-03 00:00:00.000000000 Z
|
13
75
|
dependencies:
|
14
76
|
- !ruby/object:Gem::Dependency
|
15
77
|
name: bundler
|
@@ -17,83 +79,64 @@ dependencies:
|
|
17
79
|
requirements:
|
18
80
|
- - ">="
|
19
81
|
- !ruby/object:Gem::Version
|
20
|
-
version: '
|
21
|
-
- - "<"
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: '3'
|
82
|
+
version: '0'
|
24
83
|
type: :development
|
25
84
|
prerelease: false
|
26
85
|
version_requirements: !ruby/object:Gem::Requirement
|
27
86
|
requirements:
|
28
87
|
- - ">="
|
29
88
|
- !ruby/object:Gem::Version
|
30
|
-
version: '
|
31
|
-
- - "<"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '3'
|
89
|
+
version: '0'
|
34
90
|
- !ruby/object:Gem::Dependency
|
35
|
-
name:
|
91
|
+
name: rake
|
36
92
|
requirement: !ruby/object:Gem::Requirement
|
37
93
|
requirements:
|
38
|
-
- - "
|
94
|
+
- - ">="
|
39
95
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
96
|
+
version: '0'
|
41
97
|
type: :development
|
42
98
|
prerelease: false
|
43
99
|
version_requirements: !ruby/object:Gem::Requirement
|
44
100
|
requirements:
|
45
|
-
- - "
|
101
|
+
- - ">="
|
46
102
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
103
|
+
version: '0'
|
48
104
|
- !ruby/object:Gem::Dependency
|
49
|
-
name:
|
105
|
+
name: rspec
|
50
106
|
requirement: !ruby/object:Gem::Requirement
|
51
107
|
requirements:
|
52
|
-
- - "
|
108
|
+
- - "~>"
|
53
109
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
110
|
+
version: '3.4'
|
55
111
|
type: :development
|
56
112
|
prerelease: false
|
57
113
|
version_requirements: !ruby/object:Gem::Requirement
|
58
114
|
requirements:
|
59
|
-
- - "
|
115
|
+
- - "~>"
|
60
116
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
62
|
-
description:
|
63
|
-
#content_type, #original_filename, and #local_path will be posted as a binary file.'
|
117
|
+
version: '3.4'
|
118
|
+
description:
|
64
119
|
email:
|
65
|
-
- nick@nicksieger.com
|
66
|
-
- samuel.williams@oriontransfer.co.nz
|
67
120
|
executables: []
|
68
121
|
extensions: []
|
69
122
|
extra_rdoc_files: []
|
70
123
|
files:
|
71
|
-
- ".gitignore"
|
72
|
-
- ".rspec"
|
73
|
-
- ".travis.yml"
|
74
|
-
- ".yardopts"
|
75
|
-
- Gemfile
|
76
|
-
- History.txt
|
77
|
-
- LICENSE
|
78
|
-
- Manifest.txt
|
79
|
-
- README.md
|
80
|
-
- Rakefile
|
81
124
|
- lib/composite_io.rb
|
125
|
+
- lib/multipart/post.rb
|
126
|
+
- lib/multipart/post/composite_read_io.rb
|
127
|
+
- lib/multipart/post/multipartable.rb
|
128
|
+
- lib/multipart/post/parts.rb
|
129
|
+
- lib/multipart/post/upload_io.rb
|
130
|
+
- lib/multipart/post/version.rb
|
82
131
|
- lib/multipart_post.rb
|
83
132
|
- lib/multipartable.rb
|
84
133
|
- lib/net/http/post/multipart.rb
|
85
134
|
- lib/parts.rb
|
86
|
-
|
87
|
-
- spec/composite_io_spec.rb
|
88
|
-
- spec/multibyte.txt
|
89
|
-
- spec/net/http/post/multipart_spec.rb
|
90
|
-
- spec/parts_spec.rb
|
91
|
-
- spec/spec_helper.rb
|
92
|
-
homepage: https://github.com/nicksieger/multipart-post
|
135
|
+
homepage: https://github.com/socketry/multipart-post
|
93
136
|
licenses:
|
94
137
|
- MIT
|
95
138
|
metadata: {}
|
96
|
-
post_install_message:
|
139
|
+
post_install_message:
|
97
140
|
rdoc_options: []
|
98
141
|
require_paths:
|
99
142
|
- lib
|
@@ -108,13 +151,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
151
|
- !ruby/object:Gem::Version
|
109
152
|
version: '0'
|
110
153
|
requirements: []
|
111
|
-
rubygems_version: 3.
|
112
|
-
signing_key:
|
154
|
+
rubygems_version: 3.3.7
|
155
|
+
signing_key:
|
113
156
|
specification_version: 4
|
114
157
|
summary: A multipart form post accessory for Net::HTTP.
|
115
|
-
test_files:
|
116
|
-
- spec/composite_io_spec.rb
|
117
|
-
- spec/multibyte.txt
|
118
|
-
- spec/net/http/post/multipart_spec.rb
|
119
|
-
- spec/parts_spec.rb
|
120
|
-
- spec/spec_helper.rb
|
158
|
+
test_files: []
|
metadata.gz.sig
ADDED
data/.gitignore
DELETED
data/.rspec
DELETED
data/.travis.yml
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
cache: bundler
|
3
|
-
|
4
|
-
rvm:
|
5
|
-
- 2.0
|
6
|
-
- 2.1
|
7
|
-
- 2.2
|
8
|
-
- 2.3
|
9
|
-
- 2.4
|
10
|
-
- 2.5
|
11
|
-
- 2.6
|
12
|
-
- ruby-head
|
13
|
-
- jruby-head
|
14
|
-
- truffleruby
|
15
|
-
|
16
|
-
matrix:
|
17
|
-
allow_failures:
|
18
|
-
- rvm: ruby-head
|
19
|
-
- rvm: jruby-head
|
20
|
-
- rvm: truffleruby
|
data/.yardopts
DELETED
data/Gemfile
DELETED
data/History.txt
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
<!--
|
2
|
-
# @markup rdoc
|
3
|
-
# @title CHANGELOG
|
4
|
-
-->
|
5
|
-
|
6
|
-
=== 2.0.0 / 2013-12-21
|
7
|
-
|
8
|
-
- Drop Ruby 1.8 compatibility
|
9
|
-
- GH #21: Fix FilePart length calculation for Ruby 1.9 when filename contains
|
10
|
-
multibyte characters (hexfet)
|
11
|
-
- GH #20: Ensure upload responds to both #content_type and #original_filename
|
12
|
-
(Steven Davidovitz)
|
13
|
-
- GH #31: Support setting headers on any part of the request (Socrates Vicente)
|
14
|
-
- GH #30: Support array values for params (Gustav Ernberg)
|
15
|
-
- GH #32: Fix respond_to? signature (Leo Cassarani)
|
16
|
-
- GH #33: Update README to markdown (Jagtesh Chadha)
|
17
|
-
- GH #35: Improved handling of array-type parameters (Steffen Grunwald)
|
18
|
-
|
19
|
-
=== 1.2.0 / 2013-02-25
|
20
|
-
|
21
|
-
- #25: Ruby 2 compatibility (thanks mislav)
|
22
|
-
|
23
|
-
=== 1.1.5 / 2012-02-12
|
24
|
-
|
25
|
-
- Fix length/bytesize of parts in 1.9 (#7, #14) (Jason Moore)
|
26
|
-
- Allow CompositeIO objects to be re-read by rewinding, like other IO
|
27
|
-
objects. (Luke Redpath)
|
28
|
-
|
29
|
-
=== 1.1.4 / 2011-11-23
|
30
|
-
|
31
|
-
- Non-functional changes in release (switch to Bundler gem tasks)
|
32
|
-
|
33
|
-
=== 1.1.3 / 2011-07-25
|
34
|
-
|
35
|
-
- More configurable header specification for parts (Gerrit Riessen)
|
36
|
-
|
37
|
-
=== 1.1.2 / 2011-05-24
|
38
|
-
|
39
|
-
- Fix CRLF file part miscalculation (Johannes Wagener)
|
40
|
-
- Fix Epilogue CRLF issue (suggestion by Neil Spring)
|
41
|
-
|
42
|
-
=== 1.1.1 / 2011-05-13
|
43
|
-
|
44
|
-
- GH# 9: Fixed Ruby 1.9.2 StringIO bug (thanks Alex Koppel)
|
45
|
-
|
46
|
-
=== 1.1.0 / 2011-01-11
|
47
|
-
|
48
|
-
- API CHANGE: UploadIO.convert! removed in favor of UploadIO.new
|
49
|
-
(Jeff Hodges)
|
50
|
-
|
51
|
-
=== 1.0.1 / 2010-04-27
|
52
|
-
|
53
|
-
- Doc updates, make gemspec based on more modern Rubygems
|
54
|
-
|
55
|
-
=== 1.0 / 2009-02-12
|
56
|
-
|
57
|
-
- Many fixes from mlooney, seems to work now. Putting the 0.9 seal of
|
58
|
-
approval on it.
|
59
|
-
|
60
|
-
=== 0.1 / 2008-08-12
|
61
|
-
|
62
|
-
* 1 major enhancement
|
63
|
-
|
64
|
-
* Birthday!
|
data/LICENSE
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
Copyright (c) 2007-2013 Nick Sieger nick@nicksieger.com
|
2
|
-
Copyright, 2017, by Samuel G. D. Williams.
|
3
|
-
|
4
|
-
MIT license.
|
5
|
-
|
6
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
7
|
-
this software and associated documentation files (the "Software"), to deal in
|
8
|
-
the Software without restriction, including without limitation the rights to
|
9
|
-
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
10
|
-
the Software, and to permit persons to whom the Software is furnished to do so,
|
11
|
-
subject to the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be included in all
|
14
|
-
copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
18
|
-
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
19
|
-
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
20
|
-
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
21
|
-
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest.txt
DELETED
data/README.md
DELETED
@@ -1,127 +0,0 @@
|
|
1
|
-
# Multipart::Post
|
2
|
-
|
3
|
-
Adds a streamy multipart form post capability to `Net::HTTP`. Also supports other
|
4
|
-
methods besides `POST`.
|
5
|
-
|
6
|
-
[](http://travis-ci.org/socketry/multipart-post)
|
7
|
-
|
8
|
-
## Features/Problems
|
9
|
-
|
10
|
-
* Appears to actually work. A good feature to have.
|
11
|
-
* Encapsulates posting of file/binary parts and name/value parameter parts, similar to
|
12
|
-
most browsers' file upload forms.
|
13
|
-
* Provides an `UploadIO` helper class to prepare IO objects for inclusion in the params
|
14
|
-
hash of the multipart post object.
|
15
|
-
|
16
|
-
## Installation
|
17
|
-
|
18
|
-
gem install multipart-post
|
19
|
-
|
20
|
-
or in your Gemfile
|
21
|
-
|
22
|
-
gem 'multipart-post'
|
23
|
-
|
24
|
-
## Usage
|
25
|
-
|
26
|
-
```ruby
|
27
|
-
require 'net/http/post/multipart'
|
28
|
-
|
29
|
-
url = URI.parse('http://www.example.com/upload')
|
30
|
-
File.open("./image.jpg") do |jpg|
|
31
|
-
req = Net::HTTP::Post::Multipart.new url.path,
|
32
|
-
"file" => UploadIO.new(jpg, "image/jpeg", "image.jpg")
|
33
|
-
res = Net::HTTP.start(url.host, url.port) do |http|
|
34
|
-
http.request(req)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
```
|
38
|
-
|
39
|
-
To post multiple files or attachments, simply include multiple parameters with
|
40
|
-
`UploadIO` values:
|
41
|
-
|
42
|
-
```ruby
|
43
|
-
require 'net/http/post/multipart'
|
44
|
-
|
45
|
-
url = URI.parse('http://www.example.com/upload')
|
46
|
-
req = Net::HTTP::Post::Multipart.new url.path,
|
47
|
-
"file1" => UploadIO.new(File.new("./image.jpg"), "image/jpeg", "image.jpg"),
|
48
|
-
"file2" => UploadIO.new(File.new("./image2.jpg"), "image/jpeg", "image2.jpg")
|
49
|
-
res = Net::HTTP.start(url.host, url.port) do |http|
|
50
|
-
http.request(req)
|
51
|
-
end
|
52
|
-
```
|
53
|
-
|
54
|
-
To post files with other normal, non-file params such as input values, you need to pass hashes to the `Multipart.new` method.
|
55
|
-
|
56
|
-
In Rails 4 for example:
|
57
|
-
|
58
|
-
```ruby
|
59
|
-
def model_params
|
60
|
-
require_params = params.require(:model).permit(:param_one, :param_two, :param_three, :avatar)
|
61
|
-
require_params[:avatar] = model_params[:avatar].present? ? UploadIO.new(model_params[:avatar].tempfile, model_params[:avatar].content_type, model_params[:avatar].original_filename) : nil
|
62
|
-
require_params
|
63
|
-
end
|
64
|
-
|
65
|
-
require 'net/http/post/multipart'
|
66
|
-
|
67
|
-
url = URI.parse('http://www.example.com/upload')
|
68
|
-
Net::HTTP.start(url.host, url.port) do |http|
|
69
|
-
req = Net::HTTP::Post::Multipart.new(url, model_params)
|
70
|
-
key = "authorization_key"
|
71
|
-
req.add_field("Authorization", key) #add to Headers
|
72
|
-
http.use_ssl = (url.scheme == "https")
|
73
|
-
http.request(req)
|
74
|
-
end
|
75
|
-
```
|
76
|
-
|
77
|
-
Or in plain ruby:
|
78
|
-
|
79
|
-
```ruby
|
80
|
-
def params(file)
|
81
|
-
params = { "description" => "A nice picture!" }
|
82
|
-
params[:datei] = UploadIO.new(file, "image/jpeg", "image.jpg")
|
83
|
-
params
|
84
|
-
end
|
85
|
-
|
86
|
-
url = URI.parse('http://www.example.com/upload')
|
87
|
-
File.open("./image.jpg") do |file|
|
88
|
-
req = Net::HTTP::Post::Multipart.new(url.path, params(file))
|
89
|
-
res = Net::HTTP.start(url.host, url.port) do |http|
|
90
|
-
return http.request(req).body
|
91
|
-
end
|
92
|
-
end
|
93
|
-
```
|
94
|
-
|
95
|
-
### Debugging
|
96
|
-
|
97
|
-
You can debug requests and responses (e.g. status codes) for all requests by adding the following code:
|
98
|
-
|
99
|
-
```ruby
|
100
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
101
|
-
http.set_debug_output($stdout)
|
102
|
-
```
|
103
|
-
|
104
|
-
## License
|
105
|
-
|
106
|
-
Released under the MIT license.
|
107
|
-
|
108
|
-
Copyright (c) 2007-2013 Nick Sieger <nick@nicksieger.com>
|
109
|
-
Copyright, 2017, by [Samuel G. D. Williams](http://www.codeotaku.com/samuel-williams).
|
110
|
-
|
111
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
112
|
-
of this software and associated documentation files (the "Software"), to deal
|
113
|
-
in the Software without restriction, including without limitation the rights
|
114
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
115
|
-
copies of the Software, and to permit persons to whom the Software is
|
116
|
-
furnished to do so, subject to the following conditions:
|
117
|
-
|
118
|
-
The above copyright notice and this permission notice shall be included in
|
119
|
-
all copies or substantial portions of the Software.
|
120
|
-
|
121
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
122
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
123
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
124
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
125
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
126
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
127
|
-
THE SOFTWARE.
|
data/Rakefile
DELETED
data/multipart-post.gemspec
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
$:.push File.expand_path("../lib", __FILE__)
|
3
|
-
require "multipart_post"
|
4
|
-
|
5
|
-
Gem::Specification.new do |spec|
|
6
|
-
spec.name = "multipart-post"
|
7
|
-
spec.version = MultipartPost::VERSION
|
8
|
-
spec.authors = ["Nick Sieger", "Samuel Williams"]
|
9
|
-
spec.email = ["nick@nicksieger.com", "samuel.williams@oriontransfer.co.nz"]
|
10
|
-
spec.homepage = "https://github.com/nicksieger/multipart-post"
|
11
|
-
spec.summary = %q{A multipart form post accessory for Net::HTTP.}
|
12
|
-
spec.license = "MIT"
|
13
|
-
spec.description = %q{Use with Net::HTTP to do multipart form postspec. IO values that have #content_type, #original_filename, and #local_path will be posted as a binary file.}
|
14
|
-
|
15
|
-
spec.files = `git ls-files`.split("\n")
|
16
|
-
spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
-
spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
-
spec.require_paths = ["lib"]
|
19
|
-
|
20
|
-
spec.add_development_dependency 'bundler', ['>= 1.3', '< 3']
|
21
|
-
spec.add_development_dependency 'rspec', '~> 3.4'
|
22
|
-
spec.add_development_dependency 'rake'
|
23
|
-
end
|