mirror of
https://gitlab1.ptb.de/waltem01/Matrix
synced 2024-12-26 03:51:45 +00:00
implement HTTP POST method
This commit is contained in:
parent
8f4e669d51
commit
c9507ed683
@ -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();
|
||||||
|
Loading…
Reference in New Issue
Block a user