Skip to content

parseContentDisposition

Functions

parseContentDisposition()

parseContentDisposition(contentDisposition, keyword): Object

解析 Content-Disposition

Parameters

ParameterTypeDefault valueDescription
contentDispositionMaybeNullish<string>undefined响应报文的 contentDisposition 属性
keywordstring'filename'解析关键词

Returns

Object

extName

extName: undefined | string

filename

filename: undefined | string

filetype

filetype: undefined | string

rawFilename

rawFilename: undefined | string

Example

ts
const contentDisposition = 'attachment; filename="example.pdf"; filename*=UTF-8\'\'example%20%E6%B5%8B%E8%AF%95.pdf';

const { rawFilename, filename, extName } = parseContentDisposition(contentDisposition)

console.log(rawFilename, filename, extName)
// rawFilename => example%20%E6%B5%8B%E8%AF%95.pdf
// filename => example 测试.pdf
// extName => .pdf