improved file uploads

This commit is contained in:
2025-07-13 12:35:48 +02:00
parent 548dd7e9ef
commit 596d7ac35d
12 changed files with 370 additions and 87 deletions

View File

@@ -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)

View File

@@ -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()