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

[REF-2157] Allow rx.download to resolve rx.get_upload_url links #2813

Merged
merged 1 commit into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion reflex/.templates/web/utils/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ export const applyEvent = async (event, socket) => {
if (event.name == "_download") {
const a = document.createElement("a");
a.hidden = true;
a.href = event.payload.url;
// Special case when linking to uploaded files
a.href = event.payload.url.replace("${getBackendURL(env.UPLOAD)}", getBackendURL(env.UPLOAD))
a.download = event.payload.filename;
a.click();
a.remove();
Expand Down
4 changes: 2 additions & 2 deletions reflex/components/core/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def get_upload_dir() -> Path:
)


def get_upload_url(file_path: str) -> str:
def get_upload_url(file_path: str) -> Var[str]:
"""Get the URL of an uploaded file.

Args:
Expand All @@ -139,7 +139,7 @@ def get_upload_url(file_path: str) -> str:
"""
Upload.is_used = True

return f"{uploaded_files_url_prefix}/{file_path}"
return Var.create_safe(f"{uploaded_files_url_prefix}/{file_path}")


def _on_drop_spec(files: Var):
Expand Down
2 changes: 1 addition & 1 deletion reflex/components/core/upload.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def get_upload_dir() -> Path: ...

uploaded_files_url_prefix: Var

def get_upload_url(file_path: str) -> str: ...
def get_upload_url(file_path: str) -> Var[str]: ...

class UploadFilesProvider(Component):
@overload
Expand Down
Loading