improved file uploads
This commit is contained in:
@@ -23,7 +23,7 @@ pub(super) async fn route(
|
||||
};
|
||||
|
||||
let file_name = field.file_name().map(str::to_owned).unwrap();
|
||||
let data = field.bytes().await.unwrap();
|
||||
let data = field.bytes().await?;
|
||||
|
||||
warren
|
||||
.upload(state.serve_dir(), rest.as_deref(), &file_name, &data)
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
use std::error::Error;
|
||||
|
||||
use axum::{
|
||||
body::Body,
|
||||
extract::multipart::MultipartError,
|
||||
http::{StatusCode, header::InvalidHeaderValue},
|
||||
response::{IntoResponse, Response},
|
||||
};
|
||||
@@ -19,6 +22,8 @@ pub enum AppError {
|
||||
Var(#[from] std::env::VarError),
|
||||
#[error("InvalidHeaderValue: {0}")]
|
||||
InvalidHeaderValue(#[from] InvalidHeaderValue),
|
||||
#[error("Multipart: {0}")]
|
||||
Multipart(#[from] MultipartError),
|
||||
}
|
||||
|
||||
impl IntoResponse for AppError {
|
||||
@@ -34,6 +39,7 @@ impl IntoResponse for AppError {
|
||||
Self::DatabaseMigration(_) => StatusCode::INTERNAL_SERVER_ERROR,
|
||||
Self::Var(_) => StatusCode::INTERNAL_SERVER_ERROR,
|
||||
Self::InvalidHeaderValue(_) => StatusCode::INTERNAL_SERVER_ERROR,
|
||||
Self::Multipart(_) => StatusCode::INTERNAL_SERVER_ERROR,
|
||||
};
|
||||
|
||||
Response::builder()
|
||||
|
||||
Reference in New Issue
Block a user