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

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