Skip to content

Instantly share code, notes, and snippets.

@spacecowb0y
Created June 9, 2023 16:06
Show Gist options
  • Save spacecowb0y/15cc0c1e563426ed338607a26030a68c to your computer and use it in GitHub Desktop.
Save spacecowb0y/15cc0c1e563426ed338607a26030a68c to your computer and use it in GitHub Desktop.
use reqwest::blocking::multipart;
use reqwest::blocking::Client;
use screenshots::Screen;
use std::{
io::Read,
time::{SystemTime, UNIX_EPOCH},
};
fn main() {
let screens = Screen::all().unwrap();
let client = Client::new();
let mut form = multipart::Form::new();
for screen in screens {
let image = screen.capture().unwrap();
let image_data = image.to_png().unwrap();
form = form.part(
"images",
multipart::Part::bytes(image_data)
.file_name(format!(
"screenshot-{}-{}.png",
screen.display_info.id,
SystemTime::now()
.duration_since(UNIX_EPOCH)
.expect("time error")
.as_secs()
))
.mime_str("image/png")
.unwrap(),
);
}
let request = client
.post("http://0.0.0.0:3000/upload")
.multipart(form)
.build()
.unwrap();
let mut response = client.execute(request).unwrap();
println!("Screenshots uploaded with status: {}", response.status());
let mut body = Vec::new();
response
.read_to_end(&mut body)
.expect("Failed to read response body");
println!("Response Body: {:?}", body);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment