def post_gyazo
browser_cmd = 'firefox'
gyazo_url = ""
idfile = ENV['HOME'] + "/.gyazo.id"
id = nil
if File.exist?(idfile)
id = File.read(idfile).chomp
else
id = Time.new.strftime("%Y%m%d%H%M%S")
File.open(idfile,"w").print(id+"\n")
end
tmpfile = "/tmp/image_upload#{$$}.png"
system import, tmpfile
imagedata = File.read(tmpfile)
File.delete(tmpfile)
boundary = '----BOUNDARYBOUNDARY----'
data = "--\#{boundary}\\r\ncontent-disposition: form-data; name=\"id\"\\r\n\\r\n\#{id}\\r\n--\#{boundary}\\r\ncontent-disposition: form-data; name=\"imagedata\"\\r\n\\r\n\#{imagedata}\\r\n\\r\n--\#{boundary}--\\r\n"
header = {
'Content-Length' => data.length.to_s,
'Content-type' => "multipart/form-data; boundary=#{boundary}"
}
Net::HTTP.start("gyazo.com", 80){|http|
res = http.post("/upload.cgi", data, header)
url = res.response.to_ary[1]
puts url
system "#{browser_cmd} #{url}"
gyazo_url = url
}
gyazo_url
end