MCPcopy Create free account
hub / github.com/FlowiseAI/Flowise / handleFileUploads

Function handleFileUploads

packages/ui/src/views/chatmessage/ChatMessage.jsx:948–1007  ·  view source on GitHub ↗
(uploads)

Source from the content-addressed store, hash-verified

946 }
947
948 const handleFileUploads = async (uploads) => {
949 if (!uploadedFiles.length) return uploads
950
951 if (fullFileUpload) {
952 const filesWithFullUploadType = uploadedFiles.filter((file) => file.type === 'file:full')
953 if (filesWithFullUploadType.length > 0) {
954 const formData = new FormData()
955 for (const file of filesWithFullUploadType) {
956 formData.append('files', file.file)
957 }
958 formData.append('chatId', chatId)
959
960 const response = await attachmentsApi.createAttachment(chatflowid, chatId, formData)
961 const data = response.data
962
963 for (const extractedFileData of data) {
964 const content = extractedFileData.content
965 const fileName = extractedFileData.name
966
967 // find matching name in previews and replace data with content
968 const uploadIndex = uploads.findIndex((upload) => upload.name === fileName)
969
970 if (uploadIndex !== -1) {
971 uploads[uploadIndex] = {
972 ...uploads[uploadIndex],
973 data: content,
974 name: fileName,
975 type: 'file:full'
976 }
977 }
978 }
979 }
980 } else if (isChatFlowAvailableForRAGFileUploads) {
981 const filesWithRAGUploadType = uploadedFiles.filter((file) => file.type === 'file:rag')
982
983 if (filesWithRAGUploadType.length > 0) {
984 const formData = new FormData()
985 for (const file of filesWithRAGUploadType) {
986 formData.append('files', file.file)
987 }
988 formData.append('chatId', chatId)
989
990 await vectorstoreApi.upsertVectorStoreWithFormData(chatflowid, formData)
991
992 // delay for vector store to be updated
993 const delay = (delayInms) => {
994 return new Promise((resolve) => setTimeout(resolve, delayInms))
995 }
996 await delay(2500) //TODO: check if embeddings can be retrieved using file name as metadata filter
997
998 uploads = uploads.map((upload) => {
999 return {
1000 ...upload,
1001 type: 'file:rag'
1002 }
1003 })
1004 }
1005 }

Callers 1

handleSubmitFunction · 0.85

Calls 1

delayFunction · 0.85

Tested by

no test coverage detected