1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use ;
use ;
// //将actix 上传保存在本地磁盘
// pub async fn save_http_files(mut payload: Multipart) -> Result<Vec<(String, String)>, Error> {
// // iterate over multipart stream
// let mut files = vec![];
// while let Some(mut field) = payload.try_next().await? {
// // A multipart/form-data stream has to contain `content_disposition`
// let content_disposition = field.content_disposition();
// let filename = content_disposition
// .get_filename().unwrap().to_string();
// let filepath = format!("./tmp/{}", Uuid::new_v4().to_string());
// let filepath_ = filepath.clone();
// // File::create is blocking operation, use threadpool
// let mut f = web::block(|| std::fs::File::create(filepath)).await??;
// // Field in turn is stream of *Bytes* object
// while let Some(chunk) = field.try_next().await? {
// // filesystem operations are blocking, we have to use threadpool
// f = web::block(move || f.write_all(&chunk).map(|_| f)).await??;
// }
// files.push((filepath_, filename));
// }
// Ok(files)
// }
// pub(crate) fn timestamp() -> i64 {
// let start = SystemTime::now();
// let since_the_epoch = start
// .duration_since(UNIX_EPOCH)
// .expect("Time went backwards");
// let ms = since_the_epoch.as_secs() as i64 * 1000i64 + (since_the_epoch.subsec_nanos() as f64 / 1_000_000.0) as i64;
// ms
// }