From f191fc646e8ad86477e4eaccc53c472e9327e29a Mon Sep 17 00:00:00 2001 From: Mercurio <47455213+NotLugozzi@users.noreply.github.com> Date: Tue, 3 Jun 2025 19:54:41 +0200 Subject: [PATCH] [API] Refactor: set upload endpoint to form-data and increase limit to 5gb per upload --- api/src/file.rs | 4 ++-- api/src/main.rs | 1 + lightcloud_app/lib/mainpage.dart | 6 +----- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/api/src/file.rs b/api/src/file.rs index e395fba..cd389a2 100644 --- a/api/src/file.rs +++ b/api/src/file.rs @@ -19,7 +19,7 @@ pub struct Upload<'r> { file: TempFile<'r>, } -#[post("/upload", data = "")] +#[post("/upload", data = "", format = "multipart/form-data")] pub async fn upload_file( pool: &State, user: AuthenticatedUser, @@ -41,7 +41,7 @@ pub async fn upload_file( let encrypted = encrypt_data(&buffer, key.as_bytes(), &nonce); let file_id = Uuid::new_v4().to_string(); - let storage_path = format!("/data/{}", file_id); + let storage_path = format!("./data/{}", file_id); fs::write(&storage_path, &encrypted).await.ok(); fs::write(format!("{}.nonce", &storage_path), &nonce).await.ok(); diff --git a/api/src/main.rs b/api/src/main.rs index 46df953..0d35c88 100644 --- a/api/src/main.rs +++ b/api/src/main.rs @@ -52,6 +52,7 @@ async fn main() -> Result<(), rocket::Error> { .merge(("limits", rocket::data::Limits::new() .limit("form", ByteUnit::Gigabyte(5)) // 5 GB .limit("file", ByteUnit::Gigabyte(1)) // 1 GB + .limit("data-form", ByteUnit::Gigabyte(5)) // 5 GB for multipart/form-data )); diff --git a/lightcloud_app/lib/mainpage.dart b/lightcloud_app/lib/mainpage.dart index a1fa240..e1bc8b5 100644 --- a/lightcloud_app/lib/mainpage.dart +++ b/lightcloud_app/lib/mainpage.dart @@ -141,11 +141,9 @@ class _MainPageState extends State { filename: file.name, ), ); - ScaffoldMessenger.of(context).showSnackBar( - const SnackBar(content: Text('Caricamento in corso...')), + SnackBar(content: Text('Caricamento di ${file.name} in corso...')), ); - final response = await request.send(); if (response.statusCode == 200 || response.statusCode == 201) { @@ -185,9 +183,7 @@ class _MainPageState extends State { ); if (response.statusCode == 200) { - // Save the file to disk if (Platform.isAndroid || Platform.isIOS) { - // Mobile platforms await FileSaver.instance.saveFile( name: file.name, bytes: response.bodyBytes,