From af90ce3578cc46045d96938c9193f4ab8b9faccc Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Mon, 12 Sep 2022 14:19:39 +0200 Subject: Use an uploads endpoint path --- src/files.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/files.rs') diff --git a/src/files.rs b/src/files.rs index b88a5b7..bcda6ab 100644 --- a/src/files.rs +++ b/src/files.rs @@ -1,4 +1,4 @@ -use crate::config::SAVE_FILE_BASE_PATH; +use crate::config::{SAVE_FILE_BASE_PATH, UPLOADS_ENDPOINT}; use crate::errors::AppError; use axum::extract::Multipart; @@ -9,7 +9,7 @@ pub async fn upload( mut multipart: Multipart, allowed_extensions: Vec<&str>, ) -> Result { - let mut save_filename = String::new(); + let mut uploaded_file = String::new(); if let Some(file) = multipart.next_field().await.unwrap() { let content_type = file.content_type().unwrap().to_string(); @@ -26,7 +26,8 @@ pub async fn upload( { let rnd = (random::() * 1000000000 as f32) as i32; - save_filename = format!("{}/{}.{}", SAVE_FILE_BASE_PATH, rnd, ext_name); + let save_filename = format!("{}/{}.{}", SAVE_FILE_BASE_PATH, rnd, ext_name); + uploaded_file = format!("{}/{}.{}", UPLOADS_ENDPOINT, rnd, ext_name); let data = file.bytes().await.unwrap(); @@ -36,8 +37,8 @@ pub async fn upload( } } - if !save_filename.is_empty() { - return Ok(save_filename); + if !uploaded_file.is_empty() { + return Ok(uploaded_file); } Err(AppError::BadRequest( -- cgit v1.2.3-71-g8e6c