route icon indicating copy to clipboard operation
route copied to clipboard

Example files.dart ContentTypes forFile returns null ContentType

Open mkhan-akhan opened this issue 12 years ago • 2 comments

In the Example in files.dart, ContentTypes.forFile returns null because _extensions map is missing a dot in the keys. path.extension(file.path) returns the extensions with a dot prefixed. Hence 'css' : CSS should be '.css' : CSS.

mkhan-akhan avatar Mar 15 '14 02:03 mkhan-akhan

It was causing my style.css to be loaded as 'text/plain' which resulted in none of the styles being applied.

mkhan-akhan avatar Mar 15 '14 04:03 mkhan-akhan

I have the same problem because Path.extension function

Gets the file extension of path: the portion of basename from the last . to the end (including the . itself).

Opposite of mkhan-akhan solution I offer left extension names "as is" but make changes in forFile method like that:

static ContentType forFile(File file) {
  String ext = path.extension(file.path);
  return _extensions[ext.length > 0 ? ext.substring(1) : ext];
}

akserg avatar Jul 29 '14 06:07 akserg