multipart 0.2 → 0.2.1
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.
- data/multipart.rb +27 -25
- metadata +3 -3
data/multipart.rb
CHANGED
|
@@ -145,23 +145,23 @@ module Net
|
|
|
145
145
|
boundary1="paranguaricutirimirruaru0xdeadbeef",
|
|
146
146
|
boundary2="paranguaricutirimirruaru0x20132")
|
|
147
147
|
|
|
148
|
-
self.content_type = "multipart/form-data
|
|
148
|
+
self.content_type = "multipart/form-data; boundary=\"#{boundary1}\""
|
|
149
149
|
|
|
150
150
|
tmp = StringIO.new('r+b')
|
|
151
151
|
|
|
152
152
|
# let's do the easy ones first
|
|
153
153
|
other_params.each do |key,val|
|
|
154
|
-
tmp.write "
|
|
155
|
-
tmp.write "content-disposition: form-data; name=\"#{key}\"\n"
|
|
156
|
-
tmp.write "\n"
|
|
157
|
-
tmp.write "#{val}"
|
|
154
|
+
tmp.write "--#{boundary1}\r\n"
|
|
155
|
+
tmp.write "content-disposition: form-data; name=\"#{key}\"\r\n"
|
|
156
|
+
tmp.write "\r\n"
|
|
157
|
+
tmp.write "#{val}\r\n"
|
|
158
158
|
end
|
|
159
159
|
|
|
160
160
|
# now handle the files...
|
|
161
161
|
files_params.each do |name, file|
|
|
162
|
-
tmp.write "\n--#{boundary1}\n"
|
|
162
|
+
tmp.write "\r\n--#{boundary1}\r\n"
|
|
163
163
|
|
|
164
|
-
# no \n
|
|
164
|
+
# no \r\n
|
|
165
165
|
tmp.write "content-disposition: form-data; name=\"#{name}\""
|
|
166
166
|
|
|
167
167
|
if not file.is_a? Enumerable
|
|
@@ -169,46 +169,48 @@ module Net
|
|
|
169
169
|
|
|
170
170
|
if file.filename
|
|
171
171
|
# right in content-dispo line
|
|
172
|
-
tmp.write "; filename=\"#{file.filename}\"\n"
|
|
172
|
+
tmp.write "; filename=\"#{file.filename}\"\r\n"
|
|
173
173
|
else
|
|
174
|
-
tmp.write "\n"
|
|
174
|
+
tmp.write "\r\n"
|
|
175
175
|
end
|
|
176
176
|
|
|
177
|
-
tmp.write "Content-Type: #{file.mimetype}\n"
|
|
178
|
-
tmp.write "Content-Transfer-Encoding: binary\n"
|
|
179
|
-
tmp.write "\n"
|
|
177
|
+
tmp.write "Content-Type: #{file.mimetype}\r\n"
|
|
178
|
+
tmp.write "Content-Transfer-Encoding: binary\r\n"
|
|
179
|
+
tmp.write "\r\n"
|
|
180
180
|
tmp.write(file.read())
|
|
181
181
|
file.maybeclose
|
|
182
182
|
else
|
|
183
183
|
# multiple-file parameter (multipart/mixed)
|
|
184
|
-
tmp.write "\n"
|
|
185
|
-
tmp.write "Content-Type: multipart/mixed
|
|
186
|
-
tmp.write " boundary=\"#{boundary2}\"\n"
|
|
184
|
+
tmp.write "\r\n"
|
|
185
|
+
tmp.write "Content-Type: multipart/mixed;"
|
|
186
|
+
tmp.write " boundary=\"#{boundary2}\"\r\n"
|
|
187
187
|
|
|
188
188
|
file.each do |f|
|
|
189
|
-
tmp.write "\n--#{boundary2}\n"
|
|
189
|
+
tmp.write "\r\n--#{boundary2}\r\n"
|
|
190
190
|
|
|
191
191
|
tmp.write "Content-disposition: attachment"
|
|
192
192
|
if f.filename
|
|
193
|
-
tmp.write "; filename=\"#{f.filename}\"\n"
|
|
193
|
+
tmp.write "; filename=\"#{f.filename}\"\r\n"
|
|
194
194
|
else
|
|
195
|
-
tmp.write "\n"
|
|
195
|
+
tmp.write "\r\n"
|
|
196
196
|
end
|
|
197
197
|
|
|
198
|
-
tmp.write "Content-Type: #{f.mimetype}\n"
|
|
199
|
-
tmp.write "Content-Transfer-Encoding: binary\n"
|
|
200
|
-
tmp.write "\n"
|
|
198
|
+
tmp.write "Content-Type: #{f.mimetype}\r\n"
|
|
199
|
+
tmp.write "Content-Transfer-Encoding: binary\r\n"
|
|
200
|
+
tmp.write "\r\n"
|
|
201
201
|
tmp.write(f.read())
|
|
202
202
|
f.maybeclose
|
|
203
203
|
end
|
|
204
|
-
tmp.write "\n--#{boundary2}\n"
|
|
204
|
+
tmp.write "\r\n--#{boundary2}--\r\n"
|
|
205
205
|
end
|
|
206
206
|
end
|
|
207
|
-
tmp.write "
|
|
208
|
-
|
|
209
|
-
tmp.flush.seek(0)
|
|
207
|
+
tmp.write "--#{boundary1}--\r\n"
|
|
210
208
|
|
|
209
|
+
|
|
210
|
+
tmp.flush
|
|
211
|
+
self.content_length = tmp.size
|
|
211
212
|
self.body_stream = tmp
|
|
213
|
+
self.body_stream.seek(0)
|
|
212
214
|
nil
|
|
213
215
|
end
|
|
214
216
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: multipart
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 0.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Leonardo Boiko
|
|
@@ -9,7 +9,7 @@ autorequire:
|
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
|
-
date:
|
|
12
|
+
date: 2009-04-04 00:00:00 -03:00
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies: []
|
|
15
15
|
|
|
@@ -45,7 +45,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
45
45
|
requirements: []
|
|
46
46
|
|
|
47
47
|
rubyforge_project: multipart
|
|
48
|
-
rubygems_version: 1.
|
|
48
|
+
rubygems_version: 1.2.0
|
|
49
49
|
signing_key:
|
|
50
50
|
specification_version: 2
|
|
51
51
|
summary: add multipart (file upload) support to Net::HTTP::Post
|