Last active
November 1, 2018 15:04
-
-
Save veer66/fc38a183e317de920c4f66266a543110 to your computer and use it in GitHub Desktop.
Upload file as multipart via https in Rust
This file contains hidden or 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
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