reflex-dev/reflex · error · ValueError
Cannot provide both URL and data to download.
Error message
Cannot provide both URL and data to download.
What it means
rx.download accepts either a url to a served file or inline data (str/bytes) to encode as a data: URI — providing both is ambiguous and rejected.
Source
Thrown at packages/reflex-base/src/reflex_base/event/__init__.py:1744
"""
from reflex_components_core.core.cond import cond
if isinstance(url, str):
if not url.startswith("/"):
msg = "The URL argument should start with a /"
raise ValueError(msg)
# if filename is not provided, infer it from url
if filename is None:
filename = url.rpartition("/")[-1]
if filename is None:
filename = ""
if data is not None:
if url is not None:
msg = "Cannot provide both URL and data to download."
raise ValueError(msg)
if isinstance(data, str):
if mime_type is None:
mime_type = "text/plain"
# Caller provided a plain text string to download.
url = f"data:{mime_type};base64," + b64encode(data.encode("utf-8")).decode(
"utf-8"
)
elif isinstance(data, Var):
if mime_type is None:
mime_type = "text/plain"
# Need to check on the frontend if the Var already looks like a data: URI.
is_data_url = (data.js_type() == "string") & (
data.to(str).startswith("data:")
)
# If it's a data: URI, use it as is, otherwise convert the Var to JSON in a data: URI.View on GitHub (pinned to 45b8ed5ab7)
Solutions
- Remove whichever of url/data you do not need
- If you have both, choose one source of truth (usually data= for dynamically generated content, url= for static assets)
Example fix
# before rx.download(url='/report.pdf', data=pdf_bytes) # after rx.download(data=pdf_bytes, filename='report.pdf')
Defensive patterns
Strategy: validation
Validate before calling
assert not (url is not None and data is not None), 'pass either url or data to rx.download'
Prevention
- Pick one source (url or data) per download call; make it explicit in helper functions
When it happens
Trigger: rx.download(url='/report.pdf', data=b'...') or rx.download(url='/x.csv', data='csv content').
Common situations: Code evolved from downloading a generated file (data=) to also passing the url where it was cached, or copy-pasting kwargs from another download call.
Related errors
- Event handler {self.fn.__name__} received repeated argument
- Event handler {self.fn.__name__} received extra argument {ex
- Event handler {self.fn.__name__} received multiple file uplo
- Event handler {self.fn.__name__} argument {clash!r} conflict
- The URL argument should start with a /
AI-assisted analysis of reflex-dev/reflex@45b8ed5ab7 (2026-08-28).
Data as JSON: /api/errors/06bd95c1fbb3df69.
Report an issue: GitHub.