mime_type 0.2.1

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 75

MIME type

Library to get MIME type from a file name. When a HTTP server sends a file to the client, MIME type of the file must be set to the Content-Type header of the response.

Only two methods are available:

  • String mime(String FileName) // gets MIME type from the file name (such as 'Hello.dart')

  • String mimeFromExtension(String extension) // gets MIME type from the extension (such as 'dart')

Both methods return null If MIME type for the file is not available.

Example

import 'package:mime_type/mime_type.dart';

sendFile(HttpRequest request, String fileName) {
  HttpResponse response = request.response;
  File file = new File(fileName);
  if (file.existsSync()) {
    String mimeType = mime(fileName);
    if (mimeType == null) mimeType = 'text/plain; charset=UTF-8';
      // you can change the default content type
      // or, you can choose to send error message
    response.headers.set('Content-Type', mimeType);
    RandomAccessFile openedFile = file.openSync();
    response.contentLength = openedFile.lengthSync();
    openedFile.closeSync();
    file.openRead().pipe(response);
  } else {
    // send 404 (Not Found) status to the client
  }
}

License

This library is licensed under [MIT License][mit]. [mit]: http://www.opensource.org/licenses/mit-license.php

Changelog

0.2.1

  • Type woff2 added.

0.2.0

  • Included Apache-types.
  • Changed MIME type for extension 'dart' from 'application/dart' to 'application/vnd.dart'.

0.1.1 to 0.1.7

  • Several types added.

0.1.0

  • First publishing.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  mime_type: ^0.2.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:mime_type/mime_type.dart';
  
Version Uploaded Documentation Archive
0.2.1 May 29, 2017 Go to the documentation of mime_type 0.2.1 Download mime_type 0.2.1 archive
0.2.0 Nov 20, 2016 Go to the documentation of mime_type 0.2.0 Download mime_type 0.2.0 archive
0.1.8 May 29, 2017 Go to the documentation of mime_type 0.1.8 Download mime_type 0.1.8 archive
0.1.7 Nov 2, 2014 Go to the documentation of mime_type 0.1.7 Download mime_type 0.1.7 archive
0.1.6 Oct 30, 2014 Go to the documentation of mime_type 0.1.6 Download mime_type 0.1.6 archive
0.1.5 Oct 9, 2014 Go to the documentation of mime_type 0.1.5 Download mime_type 0.1.5 archive
0.1.4 Oct 22, 2013 Go to the documentation of mime_type 0.1.4 Download mime_type 0.1.4 archive
0.1.3 Jul 13, 2013 Go to the documentation of mime_type 0.1.3 Download mime_type 0.1.3 archive
0.1.2 Mar 17, 2013 Go to the documentation of mime_type 0.1.2 Download mime_type 0.1.2 archive
0.1.1 Mar 9, 2013 Go to the documentation of mime_type 0.1.1 Download mime_type 0.1.1 archive

All 11 versions...

Popularity:
Describes how popular the package is relative to other packages. [more]
78
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
28
Overall:
Weighted score of the above. [more]
75
Learn more about scoring.

We analyzed this package on Oct 11, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.4

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:mime_type/mime_type.dart.

Maintenance issues and suggestions

Add SDK constraint in pubspec.yaml. (-5 points)

For information about setting SDK constraint, please see https://www.dartlang.org/tools/pub/pubspec#sdk-constraints.

Package is getting outdated. (-36.99 points)

The package was released 71 weeks ago.

The description is too short. (-20 points)

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package. Common file name patterns include: main.dart, example.dart or you could also use mime_type.dart.