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 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.
Answered by
Archmonger
Jun 15, 2023
Replies: 1 comment
-
Right now, file uploads are unsupported.
|
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Archmonger
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Right now, file uploads are unsupported.