Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/cross_file/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ print('Content of the file: $fileContent');

You will find links to the API docs on the [pub page](https://pub.dev/packages/cross_file).

## MIME types

On web, `mimeType` reflects browser-provided file metadata when available.
Native implementations do not infer MIME types from file paths or contents.
On native platforms, `mimeType` returns the value explicitly passed to the
`XFile` constructor or `XFile.fromData`, if any.

## Web Limitations

`XFile` on the web platform is backed by [Blob](https://api.dart.dev/be/180361/dart-html/Blob-class.html)
Expand Down
4 changes: 4 additions & 0 deletions packages/cross_file/lib/src/types/base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ abstract class XFileBase {
}

/// For web, it may be necessary for a file to know its MIME type.
///
/// Native implementations do not infer this value from the file path or
/// contents. On those platforms, this returns the value passed to the
/// constructor, if any.
Comment thread
faheemabbas766 marked this conversation as resolved.
Outdated
String? get mimeType {
throw UnimplementedError('.mimeType has not been implemented.');
}
Expand Down
5 changes: 5 additions & 0 deletions packages/cross_file/lib/src/types/io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class XFile extends XFileBase {
/// [length] is ignored; the parameter exists only to match the web version of
/// the constructor.
///
/// [mimeType] is not inferred from [path]. It is returned from [mimeType] only
/// if it is explicitly provided.
Comment thread
faheemabbas766 marked this conversation as resolved.
Outdated
Comment thread
faheemabbas766 marked this conversation as resolved.
Outdated
///
// ignore: use_super_parameters
XFile(
String path, {
Expand All @@ -42,6 +45,8 @@ class XFile extends XFileBase {
///
/// [name] is ignored; the parameter exists only to match the web version of
/// the constructor.
///
/// [mimeType] is returned from [mimeType] only if it is explicitly provided.
Comment thread
faheemabbas766 marked this conversation as resolved.
Outdated
XFile.fromData(
Uint8List bytes, {
String? mimeType,
Expand Down