From 846015a01e43577e558f7fbc68d7e4c6d10d0cb1 Mon Sep 17 00:00:00 2001 From: Theo Cochereau Date: Sun, 15 Nov 2026 15:25:06 +0000 Subject: [PATCH 1/2] Keep every file of a multiple file input, add sqlpage.persist_uploaded_files A file input with the multiple attribute sends several files under the same field name, but uploaded files were stored in a HashMap keyed by field name, so only the last one was kept. - RequestInfo::uploaded_files keeps every file in an UploadedFiles list. get(name) still returns a single file (the last one), so existing functions behave as before; all(name) returns every file of a field (name[] also matches name). - New sqlpage.persist_uploaded_files(field, folder, extensions, mode): persists all the files of a field and returns their paths as a JSON array (NULL when no file was sent). Extensions are all checked before anything is written. - Tests, function documentation, form 'multiple' documentation, changelog. --- CHANGELOG.md | 2 + .../sqlpage/migrations/01_documentation.sql | 2 +- .../migrations/79_persist_uploaded_files.sql | 80 ++++++++++++++++ .../database/sqlpage_functions/functions.rs | 2 + .../functions/persist_uploaded_file.rs | 49 ++++++++-- .../functions/persist_uploaded_files.rs | 40 ++++++++ .../functions/uploaded_file_mime_type.rs | 2 +- .../functions/uploaded_file_name.rs | 2 +- .../functions/uploaded_file_path.rs | 2 +- src/webserver/http_request_info.rs | 93 ++++++++++++++++++- tests/uploads/mod.rs | 77 +++++++++++++++ tests/uploads/persist_multiple.sql | 2 + 12 files changed, 337 insertions(+), 16 deletions(-) create mode 100644 examples/official-site/sqlpage/migrations/79_persist_uploaded_files.sql create mode 100644 src/webserver/database/sqlpage_functions/functions/persist_uploaded_files.rs create mode 100644 tests/uploads/persist_multiple.sql diff --git a/CHANGELOG.md b/CHANGELOG.md index e89a6baab..10f37c653 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## unreleased +- A file input with `multiple` now keeps every selected file, instead of only the last one. The new [`sqlpage.persist_uploaded_files`](https://sql-page.com/functions.sql?function=persist_uploaded_files) function saves them all and returns their paths as a JSON array. + ## v0.48.0 (2026-11-12) - Updated Rust and browser dependencies, including ApexCharts 8.8.1, Tabler 1.7.4, Tabler icons 3.51, and Tom Select 2.7. Chart series names and labels now display HTML as text, fixing upstream script injection in legends and tooltips. diff --git a/examples/official-site/sqlpage/migrations/01_documentation.sql b/examples/official-site/sqlpage/migrations/01_documentation.sql index 906df0b81..53d879b1f 100644 --- a/examples/official-site/sqlpage/migrations/01_documentation.sql +++ b/examples/official-site/sqlpage/migrations/01_documentation.sql @@ -287,7 +287,7 @@ INSERT INTO parameter(component, name, description, type, top_level, optional) S ('min', 'The minimum value to accept for an input of type number', 'REAL', FALSE, TRUE), ('max', 'The maximum value to accept for an input of type number', 'REAL', FALSE, TRUE), ('checked', 'Used only for checkboxes and radio buttons. Indicates whether the checkbox should appear as already checked.', 'BOOLEAN', FALSE, TRUE), - ('multiple', 'Used only for select elements. Indicates that multiple elements can be selected simultaneously. When using multiple, you should add square brackets after the variable name: ''my_variable[]'' as name', 'BOOLEAN', FALSE, TRUE), + ('multiple', 'For select elements, indicates that multiple elements can be selected simultaneously. When using multiple, you should add square brackets after the variable name: ''my_variable[]'' as name. For file inputs, lets the user select several files at once: save them all with [sqlpage.persist_uploaded_files](functions.sql?function=persist_uploaded_files).', 'BOOLEAN', FALSE, TRUE), ('empty_option', 'Only for inputs of type `select`. Adds an empty option with the given label before the ones defined in `options`. Useful when generating other options from a database table.', 'TEXT', FALSE, TRUE), ('searchable', 'For select and multiple-select elements, displays them with a nice dropdown that allows searching for options.', 'BOOLEAN', FALSE, TRUE), ('dropdown', 'An alias for "searchable".', 'BOOLEAN', FALSE, TRUE), diff --git a/examples/official-site/sqlpage/migrations/79_persist_uploaded_files.sql b/examples/official-site/sqlpage/migrations/79_persist_uploaded_files.sql new file mode 100644 index 000000000..a98b5139f --- /dev/null +++ b/examples/official-site/sqlpage/migrations/79_persist_uploaded_files.sql @@ -0,0 +1,80 @@ +INSERT INTO sqlpage_functions ( + "name", + "introduced_in_version", + "icon", + "description_md" + ) +VALUES ( + 'persist_uploaded_files', + '0.49.0', + 'files', + 'Persists all the files uploaded in a single form field, and returns their paths as a JSON array. +If no file was uploaded in the field, the function returns NULL. + +Use it with a file input that has the `multiple` attribute, so that users can select several files at once. +It works like [`persist_uploaded_file`](?function=persist_uploaded_file), +which only persists one file (the last one, when several were sent). + +If one of the files has an extension that is not allowed, the function fails and no file is persisted. + +### Example + +#### Photo gallery + +##### `upload_form.sql` + +```sql +select ''form'' as component, ''save_photos.sql'' as action; +select ''file'' as type, ''photos[]'' as name, ''Photos'' as label, true as multiple, ''image/*'' as accept; +``` + +##### `save_photos.sql` + +```sql +set paths = sqlpage.persist_uploaded_files(''photos'', ''photos'', ''jpg,jpeg,png,webp''); + +insert into photo (path) +select value from json_each($paths); -- PostgreSQL: json_array_elements_text($paths::json) + +select ''redirect'' as component, ''gallery.sql'' as link; +``` +' + ); +INSERT INTO sqlpage_function_parameters ( + "function", + "index", + "name", + "description_md", + "type" + ) +VALUES ( + 'persist_uploaded_files', + 1, + 'files', + 'Name of the form field containing the uploaded files. A field named `photos[]` in the form can be referenced as `photos`.', + 'TEXT' + ), + ( + 'persist_uploaded_files', + 2, + 'destination_folder', + 'Optional. Path to the folder where the files will be saved, relative to the web root. By default, the files will be saved in the `uploads` folder. + +**Security note**: this value must be a folder name you choose yourself in your SQL code (a trusted constant). Never build it from untrusted input: see [`persist_uploaded_file`](?function=persist_uploaded_file).', + 'TEXT' + ), + ( + 'persist_uploaded_files', + 3, + 'allowed_extensions', + 'Optional. Comma-separated list of allowed file extensions, checked for every file. By default: jpg,jpeg,png,gif,bmp,webp,pdf,txt,doc,docx,xls,xlsx,csv,mp3,mp4,wav,avi,mov. +Changing this may be dangerous ! If you add "sql", "svg" or "html" to the list, an attacker could execute arbitrary SQL queries on your database, or impersonate other users.', + 'TEXT' + ), + ( + 'persist_uploaded_files', + 4, + 'mode', + 'Optional. Unix permissions to set on the files, in octal notation. By default, "600" (read/write for the owner only).', + 'TEXT' + ); diff --git a/src/webserver/database/sqlpage_functions/functions.rs b/src/webserver/database/sqlpage_functions/functions.rs index 5139fa314..d92d7735c 100644 --- a/src/webserver/database/sqlpage_functions/functions.rs +++ b/src/webserver/database/sqlpage_functions/functions.rs @@ -27,6 +27,7 @@ mod link; mod oidc_logout_url; mod path; mod persist_uploaded_file; +mod persist_uploaded_files; mod protocol; mod random_string; mod read_file_as_data_url; @@ -67,6 +68,7 @@ sqlpage_functions! { oidc_logout_url, path, persist_uploaded_file, + persist_uploaded_files, protocol, random_string, read_file_as_data_url, diff --git a/src/webserver/database/sqlpage_functions/functions/persist_uploaded_file.rs b/src/webserver/database/sqlpage_functions/functions/persist_uploaded_file.rs index ac5d8ab18..d9dc8e97e 100644 --- a/src/webserver/database/sqlpage_functions/functions/persist_uploaded_file.rs +++ b/src/webserver/database/sqlpage_functions/functions/persist_uploaded_file.rs @@ -2,6 +2,8 @@ use std::borrow::Cow; use anyhow::Context; +use actix_multipart::form::tempfile::TempFile; + use crate::webserver::http_request_info::RequestInfo; use super::random_string::random_string_sync; @@ -16,13 +18,30 @@ pub(super) async fn persist_uploaded_file<'a>( allowed_extensions: Option>, mode: Option>, ) -> anyhow::Result> { - let folder = folder.unwrap_or(Cow::Borrowed("uploads")); - let allowed_extensions_str = - allowed_extensions.unwrap_or(Cow::Borrowed(DEFAULT_ALLOWED_EXTENSIONS)); - let allowed_extensions = allowed_extensions_str.split(','); - let Some(uploaded_file) = request.uploaded_files.get(&field_name.to_string()) else { + let Some(uploaded_file) = request.uploaded_files.get(&field_name) else { return Ok(None); }; + let extension = allowed_extension(uploaded_file, allowed_extensions.as_deref())?; + let path = persist_file( + request, + uploaded_file, + extension, + &field_name, + folder.as_deref(), + mode.as_deref(), + ) + .await?; + Ok(Some(path)) +} + +/// Returns the extension of the uploaded file, or an error if it is not in the allowed list. +pub(super) fn allowed_extension<'f>( + uploaded_file: &'f TempFile, + allowed_extensions: Option<&str>, +) -> anyhow::Result<&'f str> { + let allowed_extensions = allowed_extensions + .unwrap_or(DEFAULT_ALLOWED_EXTENSIONS) + .split(','); let file_name = uploaded_file.file_name.as_deref().unwrap_or_default(); let extension = file_name.split('.').next_back().unwrap_or_default(); if !allowed_extensions @@ -32,6 +51,20 @@ pub(super) async fn persist_uploaded_file<'a>( let exts = allowed_extensions.collect::>().join(", "); anyhow::bail!("file extension {extension} is not allowed. Allowed extensions: {exts}"); } + Ok(extension) +} + +/// Copies an uploaded file to `folder` (relative to the web root) under a random name, +/// and returns its path relative to the web root, with a leading slash. +pub(super) async fn persist_file( + request: &RequestInfo, + uploaded_file: &TempFile, + extension: &str, + field_name: &str, + folder: Option<&str>, + mode: Option<&str>, +) -> anyhow::Result { + let folder = folder.unwrap_or("uploads"); // Resolve the folder path relative to the web root. // `folder` is trusted application input: it is expected to be a constant chosen by the // app author in their SQL code, never attacker-controlled request data. It is joined @@ -39,7 +72,7 @@ pub(super) async fn persist_uploaded_file<'a>( // the caller write the uploaded file outside the web root. Callers must not pass // untrusted input (form fields, query parameters, headers, ...) as the folder. let web_root = &request.app_state.config.web_root; - let target_folder = web_root.join(&*folder); + let target_folder = web_root.join(folder); // create the folder if it doesn't exist tokio::fs::create_dir_all(&target_folder) .await @@ -56,7 +89,7 @@ pub(super) async fn persist_uploaded_file<'a>( target_path.display() ) })?; - set_file_mode(&target_path, mode.as_deref()).await?; + set_file_mode(&target_path, mode).await?; // remove the WEB_ROOT prefix from the path, but keep the leading slash let path = "/".to_string() + target_path @@ -68,7 +101,7 @@ pub(super) async fn persist_uploaded_file<'a>( target_path.display() ) })?; - Ok(Some(path)) + Ok(path) } #[cfg(unix)] diff --git a/src/webserver/database/sqlpage_functions/functions/persist_uploaded_files.rs b/src/webserver/database/sqlpage_functions/functions/persist_uploaded_files.rs new file mode 100644 index 000000000..d99f9e00e --- /dev/null +++ b/src/webserver/database/sqlpage_functions/functions/persist_uploaded_files.rs @@ -0,0 +1,40 @@ +use std::borrow::Cow; + +use crate::webserver::http_request_info::RequestInfo; + +use super::persist_uploaded_file::{allowed_extension, persist_file}; + +/// Persists all the files uploaded in a field (a file input with the `multiple` attribute), +/// and returns their paths as a JSON array. Returns NULL if no file was uploaded. +pub(super) async fn persist_uploaded_files<'a>( + request: &'a RequestInfo, + field_name: Cow<'a, str>, + folder: Option>, + allowed_extensions: Option>, + mode: Option>, +) -> anyhow::Result> { + let files: Vec<_> = request.uploaded_files.all(&field_name).collect(); + if files.is_empty() { + return Ok(None); + } + // Check every extension before writing anything: a rejected file leaves no partial upload behind. + let extensions = files + .iter() + .map(|file| allowed_extension(file, allowed_extensions.as_deref())) + .collect::>>()?; + let mut paths = Vec::with_capacity(files.len()); + for (file, extension) in files.into_iter().zip(extensions) { + paths.push( + persist_file( + request, + file, + extension, + &field_name, + folder.as_deref(), + mode.as_deref(), + ) + .await?, + ); + } + Ok(Some(serde_json::to_string(&paths)?)) +} diff --git a/src/webserver/database/sqlpage_functions/functions/uploaded_file_mime_type.rs b/src/webserver/database/sqlpage_functions/functions/uploaded_file_mime_type.rs index 48ed1d441..7374b08b9 100644 --- a/src/webserver/database/sqlpage_functions/functions/uploaded_file_mime_type.rs +++ b/src/webserver/database/sqlpage_functions/functions/uploaded_file_mime_type.rs @@ -28,7 +28,7 @@ pub(super) async fn uploaded_file_mime_type<'a>( ) -> Option> { let mime = request .uploaded_files - .get(&*upload_name)? + .get(&upload_name)? .content_type .as_ref()?; Some(Cow::Borrowed(mime.as_ref())) diff --git a/src/webserver/database/sqlpage_functions/functions/uploaded_file_name.rs b/src/webserver/database/sqlpage_functions/functions/uploaded_file_name.rs index 5a0961587..6a7d06811 100644 --- a/src/webserver/database/sqlpage_functions/functions/uploaded_file_name.rs +++ b/src/webserver/database/sqlpage_functions/functions/uploaded_file_name.rs @@ -8,7 +8,7 @@ pub(super) async fn uploaded_file_name<'a>( ) -> Option> { let fname = request .uploaded_files - .get(&*upload_name)? + .get(&upload_name)? .file_name .as_ref()?; Some(Cow::Borrowed(fname.as_str())) diff --git a/src/webserver/database/sqlpage_functions/functions/uploaded_file_path.rs b/src/webserver/database/sqlpage_functions/functions/uploaded_file_path.rs index a84abd8d1..8318a79c2 100644 --- a/src/webserver/database/sqlpage_functions/functions/uploaded_file_path.rs +++ b/src/webserver/database/sqlpage_functions/functions/uploaded_file_path.rs @@ -6,6 +6,6 @@ pub(super) async fn uploaded_file_path<'a>( request: &'a RequestInfo, upload_name: Cow<'a, str>, ) -> Option> { - let uploaded_file = request.uploaded_files.get(&*upload_name)?; + let uploaded_file = request.uploaded_files.get(&upload_name)?; Some(uploaded_file.file.path().to_string_lossy()) } diff --git a/src/webserver/http_request_info.rs b/src/webserver/http_request_info.rs index d969120f5..1a8c646b5 100644 --- a/src/webserver/http_request_info.rs +++ b/src/webserver/http_request_info.rs @@ -19,7 +19,6 @@ use actix_web_httpauth::headers::authorization::Basic; use anyhow::Context; use anyhow::anyhow; use std::cell::RefCell; -use std::collections::HashMap; use std::net::IpAddr; use std::rc::Rc; use std::sync::Arc; @@ -30,6 +29,47 @@ use super::request_variables::ParamMap; use super::request_variables::param_map; use super::{ActixErrorStatusExt, StatusCodeResultExt}; +/// Files uploaded with the request, in the order they were received. +/// +/// A file input with the `multiple` attribute sends several files under the same field name: +/// they are all kept, and [`UploadedFiles::all`] returns them. +#[derive(Debug, Default)] +pub struct UploadedFiles(Vec<(String, TempFile)>); + +impl UploadedFiles { + /// The file uploaded in the field `name`. If the field contains several files, returns the last one. + #[must_use] + pub fn get(&self, name: &str) -> Option<&TempFile> { + self.0 + .iter() + .rev() + .find_map(|(field, file)| (field == name).then_some(file)) + } + + /// All the files uploaded in the field `name`, in the order they were received. + /// A field named `name[]` also matches, following the convention used for multiple-value form fields. + pub fn all<'a>(&'a self, name: &'a str) -> impl Iterator + 'a { + self.0.iter().filter_map(move |(field, file)| { + let matches = field == name || field.strip_suffix("[]") == Some(name); + matches.then_some(file) + }) + } + + pub fn values(&self) -> impl Iterator { + self.0.iter().map(|(_, file)| file) + } + + #[must_use] + pub fn len(&self) -> usize { + self.0.len() + } + + #[must_use] + pub fn is_empty(&self) -> bool { + self.0.is_empty() + } +} + #[derive(Debug)] pub struct RequestInfo { pub method: actix_web::http::Method, @@ -37,7 +77,7 @@ pub struct RequestInfo { pub protocol: String, pub url_params: ParamMap, pub post_variables: ParamMap, - pub uploaded_files: Rc>, + pub uploaded_files: Rc, pub headers: ParamMap, pub client_ip: Option, pub cookies: ParamMap, @@ -148,7 +188,7 @@ pub(crate) async fn extract_request_info( headers: param_map(headers), url_params: param_map(get_variables), post_variables: param_map(post_variables), - uploaded_files: Rc::new(HashMap::from_iter(uploaded_files)), + uploaded_files: Rc::new(UploadedFiles(uploaded_files)), client_ip, cookies: param_map(cookies), basic_auth, @@ -404,10 +444,55 @@ mod test { .collect::() ); assert_eq!(request_info.uploaded_files.len(), 1); - let my_upload = &request_info.uploaded_files["my_uploaded_file"]; + let my_upload = request_info.uploaded_files.get("my_uploaded_file").unwrap(); assert_eq!(my_upload.file_name.as_ref().unwrap(), "test.txt"); assert_eq!(request_info.url_params.len(), 0); assert_eq!(std::fs::read(&my_upload.file).unwrap(), b"Hello World"); assert_eq!(request_info.url_params.len(), 0); } + + #[actix_web::test] + async fn test_extract_multiple_files_in_one_field() { + crate::telemetry::init_test_logging(); + let config = + serde_json::from_str::(r#"{"listen_on": "localhost:1234"}"#).unwrap(); + let mut service_request = TestRequest::get() + .insert_header(("content-type", "multipart/form-data;boundary=xxx")) + .set_payload( + "--xxx\r\n\ + Content-Disposition: form-data; name=\"photos[]\"; filename=\"a.txt\"\r\n\ + Content-Type: text/plain\r\n\ + \r\n\ + A\r\n\ + --xxx\r\n\ + Content-Disposition: form-data; name=\"other\"; filename=\"c.txt\"\r\n\ + Content-Type: text/plain\r\n\ + \r\n\ + C\r\n\ + --xxx\r\n\ + Content-Disposition: form-data; name=\"photos[]\"; filename=\"b.txt\"\r\n\ + Content-Type: text/plain\r\n\ + \r\n\ + B\r\n\ + --xxx--\r\n", + ) + .to_srv_request(); + let app_data = Arc::new(AppState::init(&config).await.unwrap()); + let request_ctx = + extract_request_info(&mut service_request, app_data, ServerTiming::enabled(false)) + .await + .unwrap(); + let files = &request_ctx.request().uploaded_files; + assert_eq!(files.len(), 3); + let names: Vec<_> = files + .all("photos") + .map(|f| f.file_name.as_deref().unwrap()) + .collect(); + assert_eq!(names, ["a.txt", "b.txt"]); + assert_eq!(files.all("photos[]").count(), 2); + // Backward compatible: a single-file lookup returns the last file of the field. + let last = files.get("photos[]").unwrap(); + assert_eq!(last.file_name.as_deref(), Some("b.txt")); + assert!(files.get("photos").is_none()); + } } diff --git a/tests/uploads/mod.rs b/tests/uploads/mod.rs index 9975d6acf..827c79b40 100644 --- a/tests/uploads/mod.rs +++ b/tests/uploads/mod.rs @@ -190,3 +190,80 @@ async fn test_csv_upload() -> actix_web::Result<()> { ); Ok(()) } + +fn two_files_and_one(third_file_name: &str) -> String { + format!( + "--1234567890\r\n\ + Content-Disposition: form-data; name=\"photos[]\"; filename=\"a.txt\"\r\n\ + Content-Type: text/plain\r\n\ + \r\n\ + A\r\n\ + --1234567890\r\n\ + Content-Disposition: form-data; name=\"photos[]\"; filename=\"b.txt\"\r\n\ + Content-Type: text/plain\r\n\ + \r\n\ + B\r\n\ + --1234567890\r\n\ + Content-Disposition: form-data; name=\"photos[]\"; filename=\"{third_file_name}\"\r\n\ + Content-Type: text/plain\r\n\ + \r\n\ + C\r\n\ + --1234567890--\r\n" + ) +} + +#[actix_web::test] +async fn test_persist_uploaded_files() -> actix_web::Result<()> { + let resp = response_from(multipart_request( + "/tests/uploads/persist_multiple.sql", + two_files_and_one("c.txt"), + )) + .await?; + assert_eq!(resp.status(), StatusCode::OK); + let paths: Vec = test::read_body_json(resp).await; + assert_eq!(paths.len(), 3); + let mut contents = Vec::new(); + for path in &paths { + let file_path = std::path::Path::new(path.trim_start_matches('/')); + contents.push(std::fs::read_to_string(file_path)?); + std::fs::remove_file(file_path)?; + } + assert_eq!(contents, ["A", "B", "C"]); + Ok(()) +} + +#[actix_web::test] +async fn test_persist_uploaded_files_rejects_all_on_bad_extension() -> actix_web::Result<()> { + let folder = std::path::Path::new("tests/uploads/persisted_multiple"); + let count_files = || std::fs::read_dir(folder).map_or(0, Iterator::count); + let before = count_files(); + let resp = response_from(multipart_request( + "/tests/uploads/persist_multiple.sql", + two_files_and_one("c.sql"), + )) + .await?; + let body = crate::common::read_body_string(resp).await; + assert!(body.contains("file extension sql is not allowed"), "{body}"); + assert_eq!( + count_files(), + before, + "no file must be written when one is rejected" + ); + Ok(()) +} + +#[actix_web::test] +async fn test_persist_uploaded_files_without_files() -> actix_web::Result<()> { + let resp = response_from(multipart_request( + "/tests/uploads/persist_multiple.sql", + "--1234567890\r\n\ + Content-Disposition: form-data; name=\"x\"\r\n\ + \r\n\ + 1\r\n\ + --1234567890--\r\n", + )) + .await?; + let body = crate::common::read_body_string(resp).await; + assert_eq!(body.trim(), "null"); + Ok(()) +} diff --git a/tests/uploads/persist_multiple.sql b/tests/uploads/persist_multiple.sql new file mode 100644 index 000000000..17a428ceb --- /dev/null +++ b/tests/uploads/persist_multiple.sql @@ -0,0 +1,2 @@ +select 'json' as component, + coalesce(sqlpage.persist_uploaded_files('photos', 'tests/uploads/persisted_multiple', 'txt'), 'null') as contents; From 9960b26aa70423fb695f78256cc2ffb0a7929629 Mon Sep 17 00:00:00 2001 From: Theo Cochereau Date: Sun, 15 Nov 2026 15:59:03 +0000 Subject: [PATCH 2/2] Fix flaky upload test: use a dedicated folder for the rejection test test_persist_uploaded_files_rejects_all_on_bad_extension counted the files of tests/uploads/persisted_multiple, where test_persist_uploaded_files writes concurrently, so it failed when both tests overlapped (seen on the MSSQL job). --- tests/uploads/mod.rs | 5 +++-- tests/uploads/persist_multiple_rejected.sql | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 tests/uploads/persist_multiple_rejected.sql diff --git a/tests/uploads/mod.rs b/tests/uploads/mod.rs index 827c79b40..1aa5a260f 100644 --- a/tests/uploads/mod.rs +++ b/tests/uploads/mod.rs @@ -234,11 +234,12 @@ async fn test_persist_uploaded_files() -> actix_web::Result<()> { #[actix_web::test] async fn test_persist_uploaded_files_rejects_all_on_bad_extension() -> actix_web::Result<()> { - let folder = std::path::Path::new("tests/uploads/persisted_multiple"); + // Dedicated folder: tests run in parallel, and another test persists files in persisted_multiple. + let folder = std::path::Path::new("tests/uploads/persisted_multiple_rejected"); let count_files = || std::fs::read_dir(folder).map_or(0, Iterator::count); let before = count_files(); let resp = response_from(multipart_request( - "/tests/uploads/persist_multiple.sql", + "/tests/uploads/persist_multiple_rejected.sql", two_files_and_one("c.sql"), )) .await?; diff --git a/tests/uploads/persist_multiple_rejected.sql b/tests/uploads/persist_multiple_rejected.sql new file mode 100644 index 000000000..c5d777f88 --- /dev/null +++ b/tests/uploads/persist_multiple_rejected.sql @@ -0,0 +1,2 @@ +select 'json' as component, + coalesce(sqlpage.persist_uploaded_files('photos', 'tests/uploads/persisted_multiple_rejected', 'txt'), 'null') as contents;