-
Notifications
You must be signed in to change notification settings - Fork 359
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
Conversation
If we are happy with this approach, we can merge this. Reflex-web shall also be updated to show this new code. |
upload/upload/upload.py
Outdated
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 |
There was a problem hiding this comment.
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()):
...
i'm working on revamping the upload docs for the website today/this week, so i'll change them to recommend this mechanism |
There was a problem hiding this 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.
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. |
No description provided.