implement HTTP POST method

This commit is contained in:
waltem01 2024-02-16 07:21:31 +01:00
parent 8f4e669d51
commit c9507ed683

View File

@ -16,6 +16,20 @@
await post(fdata, 'upload'); await post(fdata, 'upload');
} }
async function post(fdata: FormData, endpoint: string) {
// Append endpoint to formdata for redirection
fdata.append('endpoint', endpoint);
// Send request to be redirected to given endpoint
const response = await fetch('/api/redirect', {
method: 'POST',
body: fdata
});
// Await respose from webserver
const mdata = (await response.json()) as APIResponse;
// Basic error handling
if (!mdata.success) alert(`Error while processing '${endpoint}'!`);
}
async function fileAsDataURL(file: File, width: number, height: number): Promise<string> { async function fileAsDataURL(file: File, width: number, height: number): Promise<string> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const img = new Image(); const img = new Image();