■ get 함수를 사용해 이미지 파일을 다운로드하는 방법을 보여준다.
▶ Cargo.toml
1 2 3 4 5 6 7 8 9 10 |
[package] name = "test_project" version = "0.1.0" edition = "2021" [dependencies] tokio = { version = "1", features = ["full"] } reqwest = "0.11.4" |
▶ src/main.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
use std::fs; use std::io::Write; #[tokio::main] async fn main() { let source_url : &str = "https://blog.kakaocdn.net/dn/bcZgvb/btskiAmI1cg/pm8rWnRjBTkMnvYcxNDgDk/img.png"; let target_bytes = reqwest::get(source_url).await.unwrap().bytes().await.unwrap(); let target_file_path : &str = "download.png"; let mut file : fs::File = fs::File::create(target_file_path).unwrap(); file.write_all(&target_bytes).unwrap(); } |