Skip to content

Commit

Permalink
fix: limit file upload size to 10mb to prevent LF crashing due data r…
Browse files Browse the repository at this point in the history
…ender component limitations (langflow-ai#3870)

* 🐛 (inputFileComponent/index.tsx): add check for file size before uploading to prevent uploading files larger than the maximum allowed size

* ✨ (alerts_constants.tsx): add new constant INVALID_FILE_SIZE_ALERT to display an alert message when the file size is too large

* ✨ (constants.ts): add constant maxSizeFilesInBytes to define the maximum file size allowed for upload in bytes

* 🐛 (inputFileComponent/index.tsx): update INVALID_FILE_SIZE_ALERT parameter from 9 to 10 to match the new file size limit
🐛 (constants/constants.ts): increase maxSizeFilesInBytes constant value from 9MB to 10MB to reflect the new file size limit
  • Loading branch information
Cristhianzl authored and diogocabral committed Nov 26, 2024
1 parent 9ea985a commit d58ebdb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
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

0 comments on commit d58ebdb

Please sign in to comment.