Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: limit file upload size to 10mb to prevent LF crashing due data render component limitations #3870

Merged
merged 4 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/frontend/src/components/inputFileComponent/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { maxSizeFilesInBytes } from "@/constants/constants";
import { usePostUploadFile } from "@/controllers/API/queries/files/use-post-upload-file";
import { createFileUpload } from "@/helpers/create-file-upload";
import { useEffect } from "react";
import {
CONSOLE_ERROR_MSG,
INVALID_FILE_ALERT,
INVALID_FILE_SIZE_ALERT,
} from "../../constants/alerts_constants";
import useAlertStore from "../../stores/alertStore";
import useFlowsManagerStore from "../../stores/flowsManagerStore";
Expand Down Expand Up @@ -45,6 +47,12 @@ export default function InputFileComponent({
createFileUpload({ multiple: false, accept: fileTypes?.join(",") }).then(
(files) => {
const file = files[0];
if (file.size > maxSizeFilesInBytes) {
setErrorData({
title: INVALID_FILE_SIZE_ALERT(10),
});
return;
}
if (file) {
if (checkFileType(file.name)) {
// Upload the file
Expand Down
5 changes: 3 additions & 2 deletions src/frontend/src/constants/alerts_constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,6 @@ export const DEL_KEY_SUCCESS_ALERT = "Success! Key deleted!";
export const DEL_KEY_SUCCESS_ALERT_PLURAL = "Success! Keys deleted!";
export const FLOW_BUILD_SUCCESS_ALERT = `Flow built successfully`;
export const SAVE_SUCCESS_ALERT = "Changes saved successfully!";

// Generic Node
export const INVALID_FILE_SIZE_ALERT = (maxSizeMB) => {
return `The file size is too large. Please select a file smaller than ${maxSizeMB}MB.`;
};
2 changes: 2 additions & 0 deletions src/frontend/src/constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -915,3 +915,5 @@ export const COLOR_OPTIONS = {
amber: "var(--note-amber)",
red: "var(--note-red)",
};

export const maxSizeFilesInBytes = 10 * 1024 * 1024; // 10MB in bytes
Loading