Skip to content

Instantly share code, notes, and snippets.

Created December 21, 2016 15:19
Show Gist options
  • Save anonymous/3f70dee7f0f689034d6accac6a98f435 to your computer and use it in GitHub Desktop.
Save anonymous/3f70dee7f0f689034d6accac6a98f435 to your computer and use it in GitHub Desktop.
extern crate curl;
extern crate futures;
extern crate tokio_core;
extern crate tokio_curl;
use tokio_core::reactor::Core;
use tokio_curl::Session;
use std::fs::File;
use std::io::Read;
use curl::easy::{Easy, Form};
fn main() {
let mut lp = Core::new().unwrap();
let session = Session::new(lp.handle());
let mut a = Easy::new();
let mut form = Form::new();
let mut content = Vec::new();
let mut file = File::open("test.png").unwrap();
let size = file.read_to_end(&mut content).unwrap();
println!("Attempting to send file with {} bytes", size);
form.part("photo").buffer("test.png", content).content_type("application/octet-stream").add().unwrap();
form.part("chat_id").contents("100".as_bytes()).add().unwrap();
a.httppost(form).unwrap();
a.url("https://api.telegram.org/bot<key>/sendPhoto").unwrap();
//a.url("https://api.telegram.org/botblabla/sendPhoto").unwrap();
a.debug_function(|_, data| {
println!("{:?}", String::from_utf8_lossy(data));
}).unwrap();
a.verbose(true).unwrap();
a.write_function(|data| {
Ok(data.len())
}).unwrap();
//a.perform().unwrap();
let req = session.perform(a);
lp.run(req).unwrap();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment