import requestsAPI_URL ="http://localhost:3000/api/v1/vector/upsert/<chatflowid>"# Use form data to upload filesform_data ={"files": ("state_of_the_union.txt",open("state_of_the_union.txt", "rb"))}body_data ={"chatId":"some-session-id"}defquery(form_data): response = requests.post(API_URL, files=form_data, data=body_data)print(response)return response.json()output =query(form_data)print(output)
// Use FormData to upload fileslet formData =newFormData();formData.append("files",input.files[0]);formData.append("chatId","some-session-id");asyncfunctionquery(formData) {constresponse=awaitfetch("http://localhost:3000/api/v1/vector/upsert/<chatflowid>", { method:"POST", body: formData } );constresult=awaitresponse.json();return result;}query(formData).then((response) => {console.log(response);});
Use the Prediction API with uploads and the chatId from step 1:
With RAG file uploads, you can't work with structured data like spreadsheets or tables, and you can't perform full summarization due to lack of full context. In some cases, you might want to include all the file content directly in the prompt for an LLM, especially with models like Gemini and Claude that have longer context windows. This research paper is one of many that compare RAG with longer context windows.
To enable full file uploads, go to Chatflow Configuration, open the File Upload tab, and click the switch:
You can see the File Attachment button in the chat, where you can upload one or more files. Under the hood, the File Loader processes each file and converts it into text.
To upload files with the API:
import requestsAPI_URL ="http://localhost:3000/api/v1/prediction/<chatflowid>"defquery(payload): response = requests.post(API_URL, json=payload)return response.json()output =query({"question": "What is the data about?","chatId": "some-session-id","uploads": [ {"data": "data:text/plain;base64,TWFkYWwcy4=","type": "file:full","name": "state_of_the_union.txt","mime": "text/plain" } ]})
asyncfunctionquery(data) {constresponse=awaitfetch("http://localhost:3000/api/v1/prediction/<chatflowid>", { method:"POST", headers: {"Content-Type":"application/json" }, body:JSON.stringify(data) } );constresult=awaitresponse.json();return result;}query({"question":"What is the data about?","chatId":"some-session-id","uploads": [ {"data":"data:text/plain;base64,TWFkYWwcy4=","type":"file:full","name":"state_of_the_union.txt","mime":"text/plain" } ]}).then((response) => {console.log(response);});
As you can see in the examples, uploads require a base64 string. To get a base64 string for a file, use the Create Attachments API.