API Reference / @dasch-ng/web-utils / parseContentDisposition
Function: parseContentDisposition()
parseContentDisposition(
header):ContentDisposition|null
Defined in: content-disposition.ts:24
Parses a Content-Disposition header (RFC 6266), e.g. to name a file downloaded with fetch. Handles quoted values with escapes, unquoted tokens and filename*=UTF-8''…. Returns null for an empty header.
Path separators are not removed from the file name; strip them before using it as a path.
Parameters
header
string | null | undefined
Returns
ContentDisposition | null
Example
typescript
const response = await fetch(url);
const { filename } = parseContentDisposition(response.headers.get('Content-Disposition')) ?? {};
await download(await response.blob(), filename ?? 'download');