Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

how to copy data from event['target']['files'] to uploads folder #1054

Discussion options

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)
You must be logged in to vote

Right now, file uploads are unsupported.

Replies: 1 comment

Comment options

Right now, file uploads are unsupported.

You must be logged in to vote
0 replies
Answer selected by Archmonger
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /