Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[update] uploaded files to be saved and served separately #178

Closed
wants to merge 3 commits into from

Conversation

jackie-pc
Copy link
Contributor

No description provided.

@jackie-pc
Copy link
Contributor Author

If we are happy with this approach, we can merge this. Reflex-web shall also be updated to show this new code.

Comment on lines 102 to 107
try:
# Failure is expected if uploaded files dir is not available (e.g. when doing `reflex export`).
app.api.mount("/uploaded", StaticFiles(directory=get_uploaded_files_dir()), name="uploaded_files")
rx.console_log(f"Serving uploaded files from {get_uploaded_files_dir()} at endpoint [BACKEND_URL]/uploaded")
except Exception:
pass
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we actually do a thing like

if os.path.exists(get_uploaded_files_dir()):
    ...

@masenf
Copy link
Collaborator

masenf commented Dec 13, 2023

i'm working on revamping the upload docs for the website today/this week, so i'll change them to recommend this mechanism

Copy link
Collaborator

@masenf masenf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

playing with this a bit more, the other thing that's unclear to me is how to get a URL for the uploaded files.

from the backend, we know what port we're running on, but we have no way of reliably knowing where that is going to be accessible in the end user's deployed app (are they running load balancer? are they rewriting requests?).

from the frontend, we know what address we used to connect to the backend, and probably could infer an reasonable URL from this, but there's no good way to get that from the backend, other than something like rx.call_script("getEventURL", callback=State.retrieve_event_url).

some more thinking (and patches) are needed to really clean this up in the general case.

also, i wonder if it's possible to mount this under /_upload/files instead of /uploaded, that way users which are already directing /_upload requests to their backend with a load balancer won't need another rule to get access to the uploaded files.

@jackie-pc
Copy link
Contributor Author

Good points. I think we first need to establish the boundary between what is being managed "within-framework" vs. "without-framework". In its current state, this is an "without-framework" example. I.e. we simply show how one might expose a FastAPI endpoint to serve the uploaded stuff at any desired location. No prescription on how URLs are discovered, etc.

If we need something "within-framework", then probably we should do something within reflex repo itself.

@masenf
Copy link
Collaborator

masenf commented Feb 13, 2024

handled via #201 #202

@masenf masenf closed this Feb 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants