Created
June 10, 2009 09:25
-
-
Save minase/127116 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def build_multipart_post_data(params, boundary) | |
enter = "\r\n" | |
data = '' | |
params.each do |k,v| | |
next if v.nil? | |
data << '--' + boundary + enter | |
data << %Q[Content-Disposition: form-data; name="#{k.to_s}"] | |
if k.to_s == 'file' | |
filename = v.split('/').last | |
mimetype = file_type[v.split('.').last] | |
data << %Q[; filename="#{filename}"] + enter | |
data << %Q[Content-Type: application/octet-stream] + enter + enter | |
data << File.read(v) + enter | |
else | |
data << enter + enter | |
data << v + enter | |
end | |
end | |
data << '--' + boundary + '--' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment