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
|
use axum::{
extract::{Extension, Host, Multipart},
response::{IntoResponse, Json, Response},
};
use bytes::buf::Buf;
use futures_util::StreamExt;
pub mod storage;
use storage::{MediaStore, MediaStoreError};
/*pub fn upload() -> impl Filter<Extract = (impl Reply,), Error = Rejection> + Clone {
warp::post()
.and(crate::util::require_host())
.and(warp::multipart::form().max_length(1024 * 1024 * 150 /*mb*/))
.and_then(|host, mut form: FormData| async move {
// TODO get rid of the double unwrap() here
let file: Part = form.next().await.unwrap().unwrap();
log::debug!(
"Uploaded: {:?}, type: {:?}",
file.filename(),
file.content_type()
);
let mut data = file.stream();
while let Some(buf) = data.next().await {
// TODO save it into a file
log::debug!("buffer length: {:?}", buf.map(|b| b.remaining()));
}
Ok::<_, warp::Rejection>(warp::reply::with_header(
warp::reply::with_status("", warp::http::StatusCode::CREATED),
"Location",
"./awoo.png",
))
})
}*/
pub async fn upload<S: MediaStore>(
Host(host): Host,
upload: Multipart,
Extension(db): Extension<S>,
) -> Response {
todo!()
}
|