how to copy data from event['target']['files'] to uploads folder #1054
Answered byArchmonger
bobwatcherx asked this question in Question
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
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 importosimporttimeimportshutilfromreactpyimporthtml, component, use_statefromreactpy.backend.fastapiimportconfigurefromfastapiimportFastAPIfrompocketbaseimportPocketBasefrompocketbase.clientimportFileUploadapp=FastAPI() client=PocketBase('https://POCKETTBASE) @componentdefmyapp(): defyouupload(event): forxinevent['target']['files']: print(x) ifnotos.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() withopen(temp_file_path, "wb") asfile: 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) returnhtml.div( html.h1("hi"), html.input({"type": "file", "on_change": youupload }) ) configure(app, myapp) |
BetaWas this translation helpful?Give feedback.
Answered by Archmonger Jun 15, 2023
Replies: 1 comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Right now, file uploads are unsupported.
|
BetaWas this translation helpful?Give feedback.
0 replies
Answer selected byArchmonger
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment
Right now, file uploads are unsupported.