Skip to content

Commit

Permalink
fix(frontend): added in new env variable for file upload as it uses c…
Browse files Browse the repository at this point in the history
…lient not server - this needs to change [2024-12-21]
  • Loading branch information
CHRISCARLON committed Dec 21, 2024
1 parent 6f4d635 commit aa01c90
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
4 changes: 3 additions & 1 deletion gridwalk-ui/next.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import type { NextConfig } from "next";

const nextConfig: NextConfig = {
/* config options here */
serverActions: {
bodySizeLimit: "15mb",
},
};

export default nextConfig;
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const useFileUploader = () => {
_workspaceId: string,
onProgress?: (progress: number) => void,
onSuccess?: (data: UploadResponse) => void,
onError?: (error: string) => void,
onError?: (error: string) => void
): Promise<void> => {
const currentWorkspaceId = getWorkspaceIdFromUrl();
try {
Expand Down Expand Up @@ -80,11 +80,14 @@ export const useFileUploader = () => {
"X-File-Size": file.size.toString(),
};

const response = await fetch("http://localhost:3001/upload_layer", {
method: "POST",
headers,
body: formData,
});
const response = await fetch(
`${process.env.NEXT_PUBLIC_GRIDWALK_API}/upload_layer`,
{
method: "POST",
headers,
body: formData,
}
);

if (!response.ok) {
const errorText = await response.text();
Expand All @@ -93,7 +96,7 @@ export const useFileUploader = () => {
error: errorText,
chunkInfo,
status: response.status,
}),
})
);
}

Expand All @@ -108,21 +111,23 @@ export const useFileUploader = () => {
}

if (finalResponse) {
console.log("Upload completed, calling success callback", finalResponse);
console.log(
"Upload completed, calling success callback",
finalResponse
);
onSuccess?.({
success: true,
data: finalResponse
data: finalResponse,
});
}

} catch (err) {
const errorMessage =
err instanceof Error ? err.message : "Unknown error";
onError?.(errorMessage);
console.error("Upload error:", err);
}
},
[],
[]
);

return { uploadFile };
Expand Down

0 comments on commit aa01c90

Please sign in to comment.