How to Download A Png Image from Web Using Reqwest

Hi , I searched everywhere and found some answers as well but they are old and I can't figure out how can I do this. Can anybody help? (sorry for my english)

I think something like this should work ?

fn main() {
    let mut file = std::fs::File::create("image.png").unwrap();
    reqwest::blocking::get("https://example.com/image.png")
        .unwrap()
        .copy_to(&mut file)
        .unwrap();
}

Add error handling at your convenience.

should I enable a optional feature to use the copy_to method

@erelde was using request::blocking::get not request::get. According to a documentation, copy_of is present in blocking version.

thanks a lot

@erelde 's solution is worked thanks a lot for helping

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.