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

This commit is contained in:
Masen Furer 2024-03-11 12:29:34 -07:00 committed by GitHub
parent 4413cb4038
commit 94e750a5f1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 5 additions and 4 deletions

View File

@ -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();

View File

@ -128,7 +128,7 @@ uploaded_files_url_prefix: Var = Var.create_safe(
)
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:
@ -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):

View File

@ -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