mimeTypeForName function
- String name
MIME type for a file name, from its extension; null when the gateway would refuse it.
Implementation
String? mimeTypeForName(String name) {
final dot = name.lastIndexOf('.');
if (dot < 0) return null;
return const {
'png': 'image/png', 'jpg': 'image/jpeg', 'jpeg': 'image/jpeg', 'gif': 'image/gif', 'webp': 'image/webp', //
'heic': 'image/heic', 'heif': 'image/heif', 'pdf': 'application/pdf', 'txt': 'text/plain', 'csv': 'text/csv',
'zip': 'application/zip', 'doc': 'application/msword',
'docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'xls': 'application/vnd.ms-excel', 'xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'mp4': 'video/mp4', 'm4a': 'audio/mp4', 'mp3': 'audio/mpeg',
}[name.substring(dot + 1).toLowerCase()];
}