Find answers from the community

Updated 2 months ago

Hello! i am trying to create a service

Hello! i am trying to create a service where i can load files and create index ... does anyone know how to load the file directly to loader/PDFReader instead of the path

the code below isnt working

Plain Text
@app.post("/add-sources/")
async def create_file(file: UploadFile):
    print(file.filename)
    loader = SimpleDirectoryReader("")
    print("Processing PDF files...")
    source_doc = loader.load_data(file=file)
    return {"file_size": file.filename}
W
n
12 comments
loader = SimpleDirectoryReader(input_files=['file1_path','file2_path'])
You can temp store the file in a temp folder
once done , it removes it by itself
hmmm nice idea... so basically
when i make the api call with file as a payload
  1. create a directory
  2. copy the file in that directory
  3. load the file in PDF Reader or whatever it s
Yeah right,
If you dont want to do this you can also read the content of the file and create a document object by yourself.
document = Document(text=YOUR_FILE_TEXT)
Also no need to make directory in the first approach, just create the file and pass on the file path here: loader = SimpleDirectoryReader(input_files=['file1_path','file2_path']).load_data()
this is a problem... we cant send the local path from frontend to backend ..so i was sending the Fileitself πŸ™‚
Once you store the file temp, file path is created for that temp file. you can use that
yeah thats what my approach will be... trying it out... thanks much!
Add a reply
Sign up and join the conversation on Discord