(&self, file_path: &str, prefix: &str)
| 57 | } |
| 58 | |
| 59 | fn upload_file(&self, file_path: &str, prefix: &str) -> Result<String, Box<dyn Error>> { |
| 60 | let rt = tokio::runtime::Builder::new_current_thread() |
| 61 | .enable_all() |
| 62 | .build()?; |
| 63 | |
| 64 | rt.block_on(async { |
| 65 | let mut file = File::open(file_path)?; |
| 66 | let mut contents = Vec::new(); |
| 67 | file.read_to_end(&mut contents)?; |
| 68 | |
| 69 | let filename = std::path::Path::new(file_path) |
| 70 | .file_name() |
| 71 | .unwrap() |
| 72 | .to_str() |
| 73 | .unwrap(); |
| 74 | let key = self.generate_key(prefix, filename); |
| 75 | |
| 76 | self.client |
| 77 | .put_object() |
| 78 | .bucket(&self.bucket) |
| 79 | .key(&key) |
| 80 | .body(ByteStream::from(contents)) |
| 81 | .send() |
| 82 | .await?; |
| 83 | |
| 84 | println!("Uploaded file to s3://{}/{}", self.bucket, key); |
| 85 | Ok(key) |
| 86 | }) |
| 87 | } |
| 88 | |
| 89 | fn download_file(&self, key: &str, output_path: &str) -> Result<(), Box<dyn Error>> { |
| 90 | let rt = tokio::runtime::Builder::new_current_thread() |
no test coverage detected