{"record":{"id":"1a9a52953ce17add","repo":"reflex-dev/reflex","slug":"the-url-argument-should-start-with-a","errorCode":null,"errorMessage":"The URL argument should start with a /","messagePattern":"The URL argument should start with a /","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"packages/reflex-base/src/reflex_base/event/__init__.py","lineNumber":1732,"sourceCode":"    Args:\n        url: The URL to the file to download.\n        filename: The name that the file should be saved as after download.\n        data: The data to download.\n        mime_type: The mime type of the data to download.\n\n    Returns:\n        EventSpec: An event to download the associated file.\n\n    Raises:\n        ValueError: If the URL provided is invalid, both URL and data are provided,\n            or the data is not an expected type.\n    \"\"\"\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(","sourceCodeStart":1714,"sourceCodeEnd":1750,"githubUrl":"https://github.com/reflex-dev/reflex/blob/45b8ed5ab735f8a56bbb09a42384f030eb0208e7/packages/reflex-base/src/reflex_base/event/__init__.py#L1714-L1750","documentation":"rx.download() only supports internal/relative URLs for the url argument; string urls must begin with '/' so the framework can route the download through its server-side helper. External http(s) links are not accepted here.","triggerScenarios":"Calling rx.download(url='https://example.com/file.pdf') or rx.download(url='files/report.pdf') with a string not starting with '/'.","commonSituations":"Trying to trigger a download of an external asset, or forgetting the leading slash on a static file served from the app's public directory.","solutions":["Prefix the path with '/' if it is an app-served file: rx.download('/report.pdf')","For external URLs, open them client-side instead (e.g. rx.redirect or an <a> link), or fetch the bytes and pass data= to rx.download","Ensure the file exists under assets/ so it is served at the root path"],"exampleFix":"# before\nrx.download(url='report.pdf')\n# after\nrx.download(url='/report.pdf')","handlingStrategy":"validation","validationCode":"def valid_download_url(u: str | None) -> bool:\n    return u is None or u.startswith('/')","typeGuard":"def is_internal_url(u) -> TypeGuard[str]: return isinstance(u, str) and u.startswith('/')","tryCatchPattern":null,"preventionTips":["Use absolute app paths ('/file.pdf') for asset downloads","Use rx.redirect or plain links for external files"],"tags":["reflex","download","url-validation"],"backgroundTag":"invalid-url-format","analyzedSha":"45b8ed5ab735f8a56bbb09a42384f030eb0208e7","analyzedAt":"2026-08-28T19:25:27.644Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}