Skip to content

Commit

Permalink
Merge pull request #201 from reflex-dev/jackie-redo-upload
Browse files Browse the repository at this point in the history
Refresh upload example to use latest best practices
  • Loading branch information
jackie-pc authored Feb 13, 2024
2 parents 4c9b7d4 + 56ee13b commit 765d556
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions upload/upload/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ class State(rx.State):
is_uploading: bool

@rx.var
def file_str(self) -> str:
def files(self) -> list[str]:
"""Get the string representation of the uploaded files."""
return "\n".join(os.listdir(rx.get_asset_path()))
return os.listdir(rx.get_upload_dir())

async def handle_upload(self, files: List[rx.UploadFile]):
"""Handle the file upload."""
Expand All @@ -23,7 +23,7 @@ async def handle_upload(self, files: List[rx.UploadFile]):
# Iterate through the uploaded files.
for file in files:
upload_data = await file.read()
outfile = rx.get_asset_path(file.filename)
outfile = os.path.join(rx.get_upload_dir(), file.filename)
with open(outfile, "wb") as file_object:
file_object.write(upload_data)

Expand Down Expand Up @@ -70,15 +70,8 @@ def index():
rx.chakra.progress(is_indeterminate=True, color="blue", width="100%"),
rx.chakra.progress(value=0, width="100%"),
),
rx.chakra.text_area(
is_disabled=True,
value=State.file_str,
width="100%",
height="100%",
bg="white",
color="black",
placeholder="No File",
min_height="20em",
rx.chakra.vstack(
rx.foreach(State.files, lambda file: rx.link(file, href=rx.get_upload_url(file)))
),
)

Expand Down

0 comments on commit 765d556

Please sign in to comment.