From f86d43f5df798d52ad2cb5f4ecc5989d6ab0fc38 Mon Sep 17 00:00:00 2001 From: ctrlc03 <93448202+ctrlc03@users.noreply.github.com> Date: Thu, 4 Jul 2024 11:04:40 +0100 Subject: [PATCH] fix: ensure uploaded files are valid --- src/hooks/useMetadata.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/hooks/useMetadata.ts b/src/hooks/useMetadata.ts index d815fd69..0c122010 100644 --- a/src/hooks/useMetadata.ts +++ b/src/hooks/useMetadata.ts @@ -11,22 +11,21 @@ export function useMetadata(metadataPtr?: string): UseTRPCQueryResult | File> { return useMutation({ mutationFn: async (data: Record | File) => { - const formData = new FormData(); - + let uploadData; if (!(data instanceof File)) { const blob = new Blob([JSON.stringify(data)], { type: "application/json", }); - formData.append("file", new File([blob], "metadata.json")); + uploadData = new File([blob], "metadata.json"); } else { - formData.append("file", data); + uploadData = data; } - return fetch(`/api/blob?filename=${data instanceof File ? data.name : "metadata.json"}`, { + return fetch(`/api/blob?filename=${uploadData.name}`, { method: "POST", headers: { "Content-Type": "application/json" }, - body: formData, + body: uploadData, }).then(async (r) => { if (!r.ok) { throw new Error("Network error");