Viewing version 1.0.1. Open the latest package page.
mime_type
1.0.1MIME type library for Dart HTTP server applications.
Readme
MIME type
Library to get MIME type from a file name or a file path and get the file extension from a MIME type. 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 three methods are available:
-
String
mime(String FileName)// gets the MIME type from a file name (such as 'Hello.dart') or a file path (such as '..\Hello.dart'). -
String
mimeFromExtension(String extension)// gets the MIME type from an extension (such as 'dart') -
String
extensionFromMime(String mime)// gets extension from MIME type (returns null if there is no such mime type)
All methods return null if they cannot find a match.
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.
Changelog
Changelog
1.0.1
- Add
mjsasapplication/javascript
1.0.0
- Null safety version of version 0.3.2
0.3.2
- Hashmap speedup and updated types.
0.3.1
- Check null or empty filename to avoid crash.
0.3.0
- Added
extensionFromMimefunction to get an extension given a mime type.
0.2.7
- Support for High Efficiency Video Coding
0.2.6
- Support for High Efficiency Image File Format
0.2.5
- avoid to give false result for JPG files
0.2.4
- prepare for Uint8List SDK breaking change
0.2.3
- forward compatible change in test/apache-types_includer.dart for upcoming SDK change
0.2.2
- add dart environment information
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.
Installing
export PUB_HOSTED_URL=https://pub.mirror.p-hatan.ir
flutter pub add 'mime_type:1.0.1'pubspec.yaml
name: mime_type
version: 1.0.1
description: MIME type library for Dart HTTP server applications.
homepage: https://github.com/mitsuoka/mime_type
environment:
sdk: '>=2.12.0 <4.0.0'
Version history
| Version | Published | Archive | SHA-256 |
|---|---|---|---|
| 0.1.0 | On demand | Download | 84ae1b31…032f3d |
| 0.1.1 | On demand | Download | 8d341c67…162cc4 |
| 0.1.2 | On demand | Download | 03c1e19e…3565f9 |
| 0.1.3 | On demand | Download | 6e9add05…bfee0f |
| 0.1.4 | On demand | Download | 9e8e74cc…e20cb7 |
| 0.1.5 | On demand | Download | 292e07d7…9c70b8 |
| 0.1.6 | On demand | Download | 322bab3d…228f99 |
| 0.1.7 | On demand | Download | c95151f6…88b761 |
| 0.1.8 | On demand | Download | 60b78acd…cc79ef |
| 0.2.0 | On demand | Download | 9c1518bd…d71360 |
| 0.2.1 | On demand | Download | bc7941d5…095d67 |
| 0.2.2 | On demand | Download | 5ee19d5f…a401e1 |
| 0.2.3 | On demand | Download | a82264a8…b73d80 |
| 0.2.4 | On demand | Download | d6056319…51933f |
| 0.2.5 | On demand | Download | b4dd687e…deb823 |
| 0.2.6 | On demand | Download | 38991f91…a5efb6 |
| 0.2.7 | On demand | Download | 0e8c24db…61f54d |
| 0.3.0 | On demand | Download | 19e50364…97a2bb |
| 0.3.1 | On demand | Download | 01d7fe18…032149 |
| 0.3.2 | On demand | Download | 0ef8fdf1…bc42d1 |
| 1.0.0 | On demand | Download | 2ad6e67d…37d275 |
| 1.0.1 | Cached · Upstream SHA-256 matched | Download | d652b613…3838bb |
Dependencies
No direct dependencies declared.