Get FileName From URL
Get a Filename Out of a URL — and the Header Trap Hiding Inside
- filename
- url
Get FileName From URL is exactly what it sounds like: give it a URL, get the filename back as a clean STRING you can wire anywhere. It's a one-function "Tools" node, and it exists because ComfyUI workflows that pull things from the web always need this step and have no built-in way to do it. If you've built a workflow around a downloader node, hit the Civitai or Hugging Face API, or fetched a remote image to save locally, you've probably wanted this. The filename from a URL isn't in the graph anywhere unless a node extracts it for you.
Before you install it, know what it does not do: it doesn't read the URL path and snip the last segment. The README example shows https://example.com/path/to/file.jpg turning into file.jpg, which makes it sound like string parsing. It isn't. The node makes a real HTTP GET request (streamed, so it stops at headers instead of downloading the body) and reads the filename out of the server's Content-Disposition header. No header, no filename - no clever fallback to the URL text.
That's the trap, and it's the thing people get burned by. Most plain static hosts don't send Content-Disposition, so a perfectly ordinary file URL makes the node throw Unable to determine filename. It works reliably when the server actually names the file: downloads from Civitai, Google Cloud Storage (the code also reads the X-Goog-Filename header GCS sets), signed URLs, and anything that suggests a download. For those, it even prefers the filename* form, which handles UTF-8 filenames - so 你的模型.safetensors comes through intact instead of mojibake.
One more honest note about the mechanism: the pack advertises "handles 303 redirects," and the code has a branch for it, but Python's requests follows redirects by default. By the time the status code is checked, a 303 has already been followed and the branch is effectively dead code. Redirects still work - just not because of that branch.
Inputs and outputs
- url (
STRING, required): the URL to hit. That's the only input.
Outputs are two strings: filename (the extracted name) and url (your original URL passed straight through). In practice you mostly care about filename - wire it into a save path, a display node, or straight into whatever downloader your workflow feeds.
Install
ComfyUI Manager: search "Get FileName From URL" (pack title ComfyUI_GetFileNameFromURL) and install. Or the manual way:
cd ComfyUI/custom_nodes
git clone https://github.com/githubYiheng/ComfyUI_GetFileNameFromURL.git
Then restart ComfyUI. The only dependencies are requests - which ComfyUI already ships - and Python's cgi standard library module. No models, no heavy pip installs, no GPU work.
Gotchas
- It calls out over the network from your machine. Every run hits the URL. Keep it to URLs you trust, and don't be surprised when it's slow if the target is.
- Non-200 responses raise an exception rather than returning a string, so a dead link kills the queue. Wrap it or feed it known-good URLs.
- Python 3.13 breaks it. The pack imports
cgi, which was removed in 3.13. If you run ComfyUI on 3.13, the node won't load; on 3.12 (what the portable builds use) it's fine.
It's a small, honest utility - the kind of node you install once, forget, and never think about again. Just remember the header requirement before you blame it for a plain-file URL.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| url | STRING | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| filename | STRING | — |
| url | STRING | — |