{"record":{"id":"06bd95c1fbb3df69","repo":"reflex-dev/reflex","slug":"cannot-provide-both-url-and-data-to-download","errorCode":null,"errorMessage":"Cannot provide both URL and data to download.","messagePattern":"Cannot provide both URL and data to download\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"packages/reflex-base/src/reflex_base/event/__init__.py","lineNumber":1744,"sourceCode":"    \"\"\"\n    from reflex_components_core.core.cond import cond\n\n    if isinstance(url, str):\n        if not url.startswith(\"/\"):\n            msg = \"The URL argument should start with a /\"\n            raise ValueError(msg)\n\n        # if filename is not provided, infer it from url\n        if filename is None:\n            filename = url.rpartition(\"/\")[-1]\n\n    if filename is None:\n        filename = \"\"\n\n    if data is not None:\n        if url is not None:\n            msg = \"Cannot provide both URL and data to download.\"\n            raise ValueError(msg)\n\n        if isinstance(data, str):\n            if mime_type is None:\n                mime_type = \"text/plain\"\n            # Caller provided a plain text string to download.\n            url = f\"data:{mime_type};base64,\" + b64encode(data.encode(\"utf-8\")).decode(\n                \"utf-8\"\n            )\n        elif isinstance(data, Var):\n            if mime_type is None:\n                mime_type = \"text/plain\"\n            # Need to check on the frontend if the Var already looks like a data: URI.\n\n            is_data_url = (data.js_type() == \"string\") & (\n                data.to(str).startswith(\"data:\")\n            )\n\n            # If it's a data: URI, use it as is, otherwise convert the Var to JSON in a data: URI.","sourceCodeStart":1726,"sourceCodeEnd":1762,"githubUrl":"https://github.com/reflex-dev/reflex/blob/45b8ed5ab735f8a56bbb09a42384f030eb0208e7/packages/reflex-base/src/reflex_base/event/__init__.py#L1726-L1762","documentation":"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.","triggerScenarios":"rx.download(url='/report.pdf', data=b'...') or rx.download(url='/x.csv', data='csv content').","commonSituations":"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.","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)"],"exampleFix":"# before\nrx.download(url='/report.pdf', data=pdf_bytes)\n# after\nrx.download(data=pdf_bytes, filename='report.pdf')","handlingStrategy":"validation","validationCode":"assert not (url is not None and data is not None), 'pass either url or data to rx.download'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pick one source (url or data) per download call; make it explicit in helper functions"],"tags":["reflex","download","argument-error"],"backgroundTag":"mutually-exclusive-arguments","analyzedSha":"45b8ed5ab735f8a56bbb09a42384f030eb0208e7","analyzedAt":"2026-08-28T19:25:27.644Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}