fromContentDisposition static method
RFC 6266: prefers filename*=UTF-8''… over filename="…".
Implementation
static String? fromContentDisposition(String? header) {
if (header == null) return null;
final RegExpMatch? extended = RegExp(r"filename\*\s*=\s*([^']*)'[^']*'([^;]+)", caseSensitive: false).firstMatch(header);
if (extended != null) {
try {
return Uri.decodeComponent(extended.group(2)!.trim().replaceAll('"', ""));
} on ArgumentError {
// Fall through to the plain parameter.
}
}
final RegExpMatch? plain = RegExp(r'filename\s*=\s*(?:"((?:[^"\\]|\\.)*)"|([^;]+))', caseSensitive: false).firstMatch(header);
final String? value = plain?.group(1) ?? plain?.group(2)?.trim();
return value == null || value.isEmpty ? null : value.replaceAll(r'\"', '"');
}