Created
February 24, 2012 11:28
-
-
Save inertialbit/1900321 to your computer and use it in GitHub Desktop.
generate base64 multipart messages
This file contains 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
require 'base64' | |
cur_dir = File.dirname(File.expand_path(__FILE__)) | |
img_dir = File.join cur_dir, 'images' | |
Dir.chdir cur_dir | |
Dir.glob("*.{jpg,png}").each do |filename| | |
img = File.new(filename, 'r') | |
encoded_data = Base64.encode64 img.read | |
img.close | |
File.open(File.join(img_dir, filename), 'w+') do |file| | |
file.print "-----------------------------168072824752491622650073\r\n" | |
file.print "Content-Disposition: form-data; name=\"photo[image]\"; filename=\"#{filename}\"\r\n" | |
file.print "Content-Type: image/jpeg\r\n" | |
file.print "Content-Transfer-Encoding: Base64\r\n" | |
file.print "\r\n" | |
file.print encoded_data | |
file.print "\r\n" | |
file.print "-----------------------------168072824752491622650073--" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment