feat: sending image to the backend

This commit is contained in:
2025-04-21 11:50:45 +01:00
parent ceb045edff
commit dbb3b82b2a
2 changed files with 27 additions and 0 deletions

View File

@ -12,6 +12,7 @@ import {
type ShareEvent,
} from "tauri-plugin-sharetarget-api";
import { readFile } from "@tauri-apps/plugin-fs";
import { sendImage, sendImageFile } from "./network";
export const App = () => {
const [logs, setLogs] = createSignal<string[]>([]);
@ -54,6 +55,15 @@ export const App = () => {
};
});
createEffect(() => {
const f = file();
if (f == null) {
return;
}
sendImageFile(f.name, f);
});
return (
<>
<ImageViewer />

View File

@ -48,6 +48,23 @@ const sendImageResponseValidator = strictObject({
Status: string(),
});
export const sendImageFile = async (
imageName: string,
file: File,
): Promise<InferOutput<typeof sendImageResponseValidator>> => {
const request = getBaseAuthorizedRequest({
path: `image/${imageName}`,
body: file,
method: "POST",
});
request.headers.set("Content-Type", "application/oclet-stream");
const res = await fetch(request).then((res) => res.json());
return parse(sendImageResponseValidator, res);
};
export const sendImage = async (
imageName: string,
base64Image: string,