diff --git a/src/frontend/src/components/IOInputField/index.tsx b/src/frontend/src/components/IOInputField/index.tsx
index 3fc95d3d4..1a8bcb4a9 100644
--- a/src/frontend/src/components/IOInputField/index.tsx
+++ b/src/frontend/src/components/IOInputField/index.tsx
@@ -8,17 +8,23 @@ export default function IOInputField({
updateValue,
}: IOInputProps): JSX.Element | undefined {
function handleInputType() {
+ console.log(inputType);
+
+ const handleUpdateValue = (e) => {
+ updateValue(e, "text");
+ };
+
switch (inputType) {
case "TextInput":
return (
);
- case "fileLoader":
+ case "FileLoader":
return ;
default:
@@ -26,8 +32,8 @@ export default function IOInputField({
);
}
diff --git a/src/frontend/src/components/IOInputs/FileInput/index.tsx b/src/frontend/src/components/IOInputs/FileInput/index.tsx
index 324169342..86d33855e 100644
--- a/src/frontend/src/components/IOInputs/FileInput/index.tsx
+++ b/src/frontend/src/components/IOInputs/FileInput/index.tsx
@@ -1,8 +1,151 @@
+import { Button } from "../../ui/button";
+
+import { useEffect, useState } from "react";
+import { BASE_URL_API } from "../../../constants/constants";
+import { uploadFile } from "../../../controllers/API";
+import useFlowsManagerStore from "../../../stores/flowsManagerStore";
import { IOFileInputProps } from "../../../types/components";
+import IconComponent from "../../genericIconComponent";
export default function IOFileInput({ field, updateValue }: IOFileInputProps) {
//component to handle file upload from chatIO
- function handleCLick() {}
+ const currentFlowId = useFlowsManagerStore((state) => state.currentFlowId);
- return
;
+ const [isDragging, setIsDragging] = useState(false);
+ const [filePath, setFilePath] = useState("");
+ const [image, setImage] = useState(null);
+
+ useEffect(() => {
+ if (filePath) {
+ updateValue(filePath, "file");
+ }
+ }, [filePath]);
+
+ useEffect(() => {
+ if (field) {
+ const fileName = field.split("/")[1];
+ const flowFileId = currentFlowId.toString();
+ setImage(`${BASE_URL_API}files/images/${flowFileId}/${fileName}`);
+ }
+ }, []);
+
+ const dragOver = (e) => {
+ e.preventDefault();
+ if (e.dataTransfer.types.some((types) => types === "Files")) {
+ setIsDragging(true);
+ }
+ };
+
+ const dragEnter = (e) => {
+ if (e.dataTransfer.types.some((types) => types === "Files")) {
+ setIsDragging(true);
+ }
+ e.preventDefault();
+ };
+
+ const dragLeave = (e) => {
+ e.preventDefault();
+ setIsDragging(false);
+ };
+
+ const onDrop = (e) => {
+ e.preventDefault();
+
+ if (e.dataTransfer.files.length > 0) {
+ const file = e.dataTransfer.files[0];
+
+ upload(file);
+
+ const fileReader = new FileReader();
+ fileReader.onload = (event) => {
+ const imageDataUrl = event.target?.result as string;
+ setImage(imageDataUrl);
+ };
+ fileReader.readAsDataURL(file);
+ }
+ setIsDragging(false);
+ };
+
+ const upload = async (file) => {
+ if (file) {
+ // Check if a file was selected
+ const fileReader = new FileReader();
+ fileReader.onload = (event) => {
+ const imageDataUrl = event.target?.result as string;
+ setImage(imageDataUrl);
+
+ // Display the image on the screen
+ const imgElement = document.createElement("img");
+ imgElement.src = imageDataUrl;
+ document.body.appendChild(imgElement); // Add the image to the body or replace this with your desired location
+ };
+ fileReader.readAsDataURL(file);
+
+ uploadFile(file, currentFlowId)
+ .then((res) => res.data)
+ .then((data) => {
+ console.log("File uploaded successfully");
+ // Get the file name from the response
+ const { file_path, flowId } = data;
+ setFilePath(file_path);
+ })
+ .catch(() => {
+ console.error("Error occurred while uploading file");
+ });
+ }
+ };
+
+ const handleButtonClick = (): void => {
+ // Create a file input element
+ const input = document.createElement("input");
+ input.type = "file";
+ input.style.display = "none"; // Hidden from view
+ input.multiple = false; // Allow only one file selection
+ input.onchange = (event: Event): void => {
+ // Get the selected file
+ const file = (event.target as HTMLInputElement).files?.[0];
+ upload(file);
+ };
+ // Trigger the file selection dialog
+ input.click();
+ };
+
+ return (
+ <>
+
+ {!isDragging && (
+
+ )}
+
+ {isDragging ? (
+ <>
+
+ "Drop your file here"
+ >
+ ) : image ? (
+

+ ) : (
+ <>
+
+ >
+ )}
+
+ >
+ );
}
diff --git a/src/frontend/src/components/IOview/index.tsx b/src/frontend/src/components/IOview/index.tsx
index 520a4a3e8..6a1e4e74c 100644
--- a/src/frontend/src/components/IOview/index.tsx
+++ b/src/frontend/src/components/IOview/index.tsx
@@ -67,15 +67,26 @@ export default function IOView(): JSX.Element {
{node && (
{
- e.target.value;
- if (node) {
- let newNode = cloneDeep(node);
- newNode.data.node!.template["value"].value =
- e.target.value;
- setNode(node.id, newNode);
+ updateValue={(e, type) => {
+ if (type === "file") {
+ if (node) {
+ let newNode = cloneDeep(node);
+ newNode.data.node!.template["file_path"].value =
+ e;
+ setNode(node.id, newNode);
+ }
+ } else {
+ if (node) {
+ let newNode = cloneDeep(node);
+ newNode.data.node!.template["value"].value =
+ e.target.value;
+ setNode(node.id, newNode);
+ }
}
}}
/>
diff --git a/src/frontend/src/constants/constants.ts b/src/frontend/src/constants/constants.ts
index 4d9ba0451..64677f728 100644
--- a/src/frontend/src/constants/constants.ts
+++ b/src/frontend/src/constants/constants.ts
@@ -519,6 +519,8 @@ export const ADMIN_HEADER_DESCRIPTION =
export const BASE_URL_API = "/api/v1/";
+export const BACKEND_URL = "http://localhost:7860/";
+
/**
* URLs excluded from error retries.
* @constant
diff --git a/src/frontend/src/controllers/API/index.ts b/src/frontend/src/controllers/API/index.ts
index ecd284876..dc6feefd7 100644
--- a/src/frontend/src/controllers/API/index.ts
+++ b/src/frontend/src/controllers/API/index.ts
@@ -865,3 +865,7 @@ export async function postBuildVertex(
): Promise> {
return await api.post(`${BASE_URL_API}build/${flowId}/vertices/${vertexId}`);
}
+
+export async function downloadImage({ flowId, fileName }): Promise {
+ return await api.get(`${BASE_URL_API}files/images/${flowId}/${fileName}`);
+}
diff --git a/src/frontend/src/types/components/index.ts b/src/frontend/src/types/components/index.ts
index 1181b0afc..2d76d611c 100644
--- a/src/frontend/src/types/components/index.ts
+++ b/src/frontend/src/types/components/index.ts
@@ -650,10 +650,10 @@ export type dropdownButtonPropsType = {
export type IOInputProps = {
inputType: string;
field: TemplateVariableType;
- updateValue: (e: any) => void;
+ updateValue: (e: any, type: string) => void;
};
export type IOFileInputProps = {
field: TemplateVariableType;
- updateValue: (e: any) => void;
+ updateValue: (e: any, type: string) => void;
};