This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::collections::HashMap; | |
use bytes::BufMut; | |
use futures::{StreamExt, TryStreamExt}; | |
use std::convert::Infallible; | |
use std::fs; | |
use std::path::Path; | |
use uuid::Uuid; | |
use warp::{http::StatusCode, http::HeaderMap, multipart::{FormData, Part}, Filter, Rejection, Reply, Stream}; | |
#[tokio::main] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async fn upload(form: FormData) -> Result<impl Reply, Rejection> { | |
let parts: Vec<Part> = form.try_collect().await.map_err(|e| { | |
eprintln!("form error: {}", e); | |
warp::reject::reject() | |
})?; | |
let mut response = HashMap::new(); | |
for p in parts { | |
if p.name() == "file" { | |
let content_type = p.content_type(); |