feat: sending image to the backend
This commit is contained in:
@ -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 />
|
||||
|
@ -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,
|
||||
|
Reference in New Issue
Block a user