Skip to content

Instantly share code, notes, and snippets.

@veer66
Last active November 1, 2018 15:04
Show Gist options
  • Save veer66/fc38a183e317de920c4f66266a543110 to your computer and use it in GitHub Desktop.
Save veer66/fc38a183e317de920c4f66266a543110 to your computer and use it in GitHub Desktop.
Upload file as multipart via https in Rust
extern crate hyper;
extern crate multipart;
extern crate hyper_native_tls;
use hyper::Client;
use hyper::net::HttpsConnector;
use hyper_native_tls::NativeTlsClient;
use multipart::client::lazy::Multipart;
use std::io::Read;
fn main() {
let ssl = NativeTlsClient::new().unwrap();
let connector = HttpsConnector::new(ssl);
let client = Client::with_connector(connector);
let mut _resp = Multipart::new()
.add_file("file", "your-file.txt")
.client_request(&client, "https://your-end-point-url")
.unwrap();
let mut s = String::new();
_resp.read_to_string(&mut s).unwrap();
println!("{}", s);
}
// hyper = "0.10"
// hyper-native-tls = "0.2.4"
// multipart = "0.13.1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment