peparing for file upload on server side

This commit is contained in:
2025-09-30 15:17:00 +02:00
parent 06118365b8
commit f9941bceba
9 changed files with 34 additions and 11 deletions

View File

@@ -42,7 +42,8 @@ subprojects {
testImplementation("org.junit.jupiter:junit-jupiter")
implementation("de.srsoftware:configuration.api:1.0.2")
implementation("de.srsoftware:tools.jdbc:2.0.0")
implementation("de.srsoftware:tools.http:6.0.4")
implementation("de.srsoftware:tools.http:6.0.5")
implementation("de.srsoftware:tools.mime:1.1.3")
implementation("de.srsoftware:tools.logging:1.3.2")
implementation("de.srsoftware:tools.optionals:1.0.0")
implementation("de.srsoftware:tools.util:2.0.4")

View File

@@ -10,7 +10,6 @@ repositories {
}
dependencies {
implementation("de.srsoftware:tools.mime:1.1.2")
implementation("de.srsoftware:tools.util:2.0.4")
implementation("org.xerial:sqlite-jdbc:3.49.0.0")
testImplementation(platform("org.junit:junit-bom:5.10.0"))

View File

@@ -9,6 +9,4 @@ dependencies{
implementation("de.srsoftware:document.file:1.0.1")
implementation("de.srsoftware:document.processor:1.0.3")
implementation("de.srsoftware:document.zugferd:1.0.5")
implementation("de.srsoftware:tools.mime:1.1.2")
}

View File

@@ -1,6 +1,7 @@
/* © SRSoftware 2025 */
package de.srsoftware.umbrella.files;
import static de.srsoftware.tools.MimeType.MIME_FORM_DATA;
import static de.srsoftware.umbrella.core.ConnectionProvider.connect;
import static de.srsoftware.umbrella.core.Constants.*;
import static de.srsoftware.umbrella.core.ModuleRegistry.*;
@@ -220,6 +221,13 @@ public class FileModule extends BaseHandler implements FileService {
if (!path.empty()) filename += "/"+URLDecoder.decode(path.toString(),UTF_8);
if (uid != user.id() && !fileDb.isPermitted(user,filename)) throw forbidden("You are not allowed to access {0}",filename);
var file = new File(baseDir+filename);
var contentType = contentType(ex).orElse(null);
if (MIME_FORM_DATA.equals(contentType)) { // file upload
// TODO: create parent directory if it does not exist
// TODO: create file and write content
return false;
}
if (file.exists()) throw unprocessable("{0} already exists!",filename);
try {
file.mkdirs();

View File

@@ -9,6 +9,7 @@
const router = useTinyRouter();
let children = $state({});
let new_dir = $state(null);
let files = $state();
let parent = $state(false);
let form = $state(false);
let path = $state(null)
@@ -95,6 +96,26 @@
return false;
}
async function upload_file(ev){
ev.preventDefault();
console.log(files);
const dataArray = new FormData();
dataArray.append("uploadFile", files);
const url = api('files'+path);
const resp = fetch(url, {
credentials: 'include',
method: 'POST',
headers: [["Content-Type", "multipart/form-data"]],
body: dataArray
});
if (resp.ok){
yikes();
} else {
error(resp);
}
return false;
}
onMount(() => loadChildren(window.location.pathname));
</script>
@@ -134,10 +155,10 @@ parent: {parent}
{/if}
{#if form}
<li class="action">
<form>
<form onsubmit={upload_file}>
<span class="symbol">+</span>
<input type="file" />
<button>{t('upload_file')}</button>
<input type="file" bind:files />
<button disabled={!files}>{t('upload_file')}</button>
</form>
</li>
{/if}

View File

@@ -3,7 +3,6 @@ description = "Umbrella : Legacy API"
dependencies{
implementation(project(":core"))
implementation(project(":user"))
implementation("de.srsoftware:tools.mime:1.1.2")
implementation("de.srsoftware:tools.web:1.3.16")
implementation("org.bitbucket.b_c:jose4j:0.9.6")
implementation("org.xerial:sqlite-jdbc:3.49.0.0")

View File

@@ -2,5 +2,4 @@ description = "Umbrella : MarkdownCompanies renderer"
dependencies{
implementation(project(":core"))
implementation("de.srsoftware:tools.mime:1.1.2")
}

View File

@@ -3,7 +3,6 @@ description = "Umbrella : Message subsystem"
dependencies{
implementation(project(":core"))
implementation("com.sun.mail:jakarta.mail:2.0.1")
implementation("de.srsoftware:tools.mime:1.1.2")
implementation("org.bitbucket.b_c:jose4j:0.9.6")
implementation("org.xerial:sqlite-jdbc:3.49.0.0")
}

View File

@@ -3,7 +3,6 @@ description = "Umbrella : User"
dependencies{
implementation(project(":core"))
implementation(project(":messages"))
implementation("de.srsoftware:tools.mime:1.1.2")
implementation("org.bitbucket.b_c:jose4j:0.9.6")
implementation("org.xerial:sqlite-jdbc:3.49.0.0")
}