What am i doing wrong!(reqwest crate)

⚓ Rust    📅 2025-09-04    👤 surdeus    👁️ 2      

surdeus

I am using reqwest crate to post a file to https://temp.sh/ but every time getting Upload failed: 404 Not Found.
Here is what I have done:

use futures::stream::TryStreamExt;
use reqwest::{Body, Client};
use std::{fs, path::PathBuf};
use tokio::fs::File;
use tokio_util::codec::{BytesCodec, FramedRead};
#[tokio::main]

async fn main() -> Result<(), Box<dyn std::error::Error>> {
   let file = rfd::FileDialog::new()
        .set_title("Select the file")
        .pick_file();

    let file: PathBuf = match file {
        Some(f) => f,
        None => {
            eprintln!("❌ No file selected.");
            return Ok(());
        }
    };

    let data = fs::read(&file)?; // read entire file into memory
    let filename = file.file_name().unwrap().to_string_lossy().to_string();

    let url = format!("https://temp.sh/{}", filename);

    let client = Client::new();
    let res = client
        .put(&url) // temp.sh requires PUT
        .body(data)
        .send()
        .await?;
    if res.status().is_success() {
        println!("✅ Uploaded");
    } else {
        eprintln!("❌ Upload failed: {}", res.status());
    }

    Ok(())
}

Corresponding curl command is curl -F "file=@test.txt" https://temp.sh/upload

What am i doing wrong?

2 posts - 2 participants

Read full topic

🏷️ Rust_feed