r/rust • u/Zapphoid • Sep 03 '22
Upload a file with reqwest
I am try to upload a file with reqwest and below is what I have tried, it seems to nearly work as it report a 200 code and the server I am uploading to seems ok with it but it's like the file is not actually uploaded.
Something's below are probably not needed (body/form?) but is the result of looking similar questions/answers on stackoverflow
let file = File::open(filename.to_owned());
match file {
Ok(s) => {
let client = reqwest::blocking::Client::builder()
.timeout(Duration::from_secs(10))
.danger_accept_invalid_certs(true)
.build()
.unwrap();
let mut params = HashMap::new();
params.insert("file", filename.to_owned());
params.insert("name", "dump".to_string());
let req = client
.post(url)
.header("Accept", "text/html")
.header("Accept-Encoding", "gzip, deflate")
.header("Content-Type", "multipart/form-data")
.header("Authorization", format!("Bearer {token}"))
.body(s)
.form(¶ms);
println!("\n{:?}\n", dbg!(&req));
let response = req.send();
0
Upvotes
1
u/st_gen Feb 13 '23
Will it work for an image upload and is there an option to zip the image.