-
-
Notifications
You must be signed in to change notification settings - Fork 328
how to copy data from event['target']['files'] to uploads folder #1054
Answered
by
Archmonger
bobwatcherx
asked this question in
Question
-
i want to upload the files i uploaded to my uploads folder. but at the moment it doesn't work is there complete documentation and fix it
code
import os import time import shutil from reactpy import html, component, use_state from reactpy.backend.fastapi import configure from fastapi import FastAPI from pocketbase import PocketBase from pocketbase.client import FileUpload app = FastAPI() client = PocketBase('https://POCKETTBASE) @component def myapp(): def youupload(event): for x in event['target']['files']: print(x) if not os.path.exists("uploads"): os.makedirs("uploads") timestamp = str(int(time.time())) file_name = timestamp + "_" + x['name'] file_path = os.path.join("uploads", file_name) temp_file_path = os.path.join("uploads", file_name) data = x.read() with open(temp_file_path, "wb") as file: file.write(data) shutil.copy(temp_file_path, file_path) result = client.collection("simple").create({ "file_name": FileUpload((youfile, open(youfile, "rb"))), }) os.remove(temp_file_path) return html.div( html.h1("hi"), html.input({ "type": "file", "on_change": youupload }) ) configure(app, myapp)
Beta Was this translation helpful? Give feedback.
All reactions
Answered by
Archmonger
Jun 15, 2023
Right now, file uploads are unsupported.
- Issue: #574
Replies: 1 comment
-
Right now, file uploads are unsupported.
- Issue: Serialize File Content #574
Beta Was this translation helpful? Give feedback.
All reactions
0 replies
Answer selected by
Archmonger
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment