Skip to content
Latchkey

wget --content-disposition: Use the Server Filename

wget --content-disposition names the saved file from the server’s Content-Disposition header instead of the URL path.

Download endpoints often serve a generic URL but set the real filename in a header. This flag honors that name so you get app-1.2.0.tar.gz, not download.

What it does

wget --content-disposition reads the Content-Disposition response header and uses its filename for the local file. Without it, wget names the file from the last path component of the URL, which for redirecting download endpoints is often wrong or generic.

Common usage

Terminal
wget --content-disposition \
  https://example.com/download?id=app-latest
# combine with a directory prefix
wget --content-disposition -P ./dist \
  https://example.com/download?id=app-latest

Options

FlagWhat it does
--content-dispositionName the file from the Content-Disposition header
-P <dir>Directory to save into (name still from the header)
--trust-server-namesOn redirect, use the final URL for the name
-O <file>Override the name entirely (ignores the header)

In CI

Use --content-disposition when an endpoint hides the real name behind a query string, so the artifact lands with its versioned filename. Note that to learn the name wget must make an extra request, so it cannot stream to stdout the same way. If you need a fixed name regardless, use -O instead.

Common errors in CI

The file saving under the query string (download?id=app-latest) means --content-disposition was not used or the server sent no such header. A later step not finding the file usually means it was named by the header and you guessed the name; list the directory or use -O to pin it.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →