I am trying to create a frontend page with NiceGUI in which I upload a file to a FastAPI backend using requests. I have tried some stuff which I found online, but to no avail
Thank you for the help!
PS. I am new to coding
from client I wrote:
def handle_upload(event: events.UploadEventArguments):
ui.notify(f'Uploaded {event.name}')
with event.content as f:
print(f.read().decode())
files = {"file": ui.upload(on_upload=handle_upload)}
r = requests.post("http://127.0.0.1:8000/docs#/default/create_upload_file_uploadfile__post")
ui.run()
ideally I would like to receive the file as a PDF, or in some way so I can read it
From server:
@app.post("/uploadfile/")
async def create_upload_file(file: UploadFile = File):
# create a copy of the temp file to "Uploaded Files"
with open(f"Uploaded Files\{file.filename}", "wb") as stored_file:
shutil.copyfileobj(file.file, stored_file)
stored_file_path = str(pathlib.Path().absolute()) + f"\\Uploaded Files\\{file.filename}"