AWSFile class abstract
A cross-platform abstraction over a read-only file.
If you are using XFile
from the
cross_file package, you can create
an AWSFile using the AWSFile.fromStream factory, e.g.
final xFile = XFile('path/to/file.txt');
final awsFile = AWSFile.fromStream(xFile.openRead());
If you are using PlatformFile
from the
file_picker package, you can
create an AWSFile using the AWSFile.fromStream factory, e.g.
final pickResult = await FilePicker.platform.pickFiles();
final pickedFile = pickResult.first;
final awsFile = AWSFile.fromStream(pickedFile.readStream);
You can also create an AWSFile by providing a file path or file bytes to AWSFile.fromPath or AWSFile.fromData, respectively.
If you are developing a Web only App, and want to use the dart:html
File
or Blob
types, you can import AWSFilePlatform
directly which provides
fromFile
and fromBlob
factories to create an AWSFile, e.g.
import 'dart:html' as html;
import 'package:aws_common/web.dart';
AWSFile convertHtmlFileOrBlob(html.Blob file) {
return AWSFilePlatform.fromBlob(file);
}
If you are developing a native only App, and want to use a dart:io
File
, you can import AWSFilePlatform
directly which provides a
fromFile
factory to create an AWSFile, e.g.
import 'dart:html' as io;
import 'package:aws_common/vm.dart';
AWSFile convertIOFile(io.File file) {
return AWSFilePlatform.fromFile(file);
}
Constructors
-
AWSFile.fromData(List<
int> data, {String? name, String? contentType}) -
Create an AWSFile from a list of bytes.
factory
- AWSFile.fromPath(String path, {String? name, String? contentType})
-
Creates an AWSFile from a path, optionally specifying a file
name
.factory -
AWSFile.fromStream(Stream<
List< stream, {String? name, String? contentType, required int size})int> > -
Creates an AWSFile from a stream of bytes, optionally specifying a file
name
andcontentType
.factory -
AWSFile.protected({String? path, List<
int> ? bytes, String? name, String? contentType}) - Protected constructor of AWSFile.
Properties
-
bytes
→ List<
int> ? -
The cached bytes content of the file.
final
-
contentType
→ Future<
String?> -
The content type of the file if provided.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- name → String?
-
The name of the file if provided or read from OS.
final
- path → String?
-
The path of the file if provided.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
size
→ Future<
int> -
Size of the file.
no setter
-
stream
→ Stream<
List< int> > -
Stream of the file content.
no setter
Methods
-
getChunkedStreamReader(
) → ChunkedStreamReader< int> -
Returns a
ChunkedStreamReader
over the stream of bytes of the file. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
openRead(
[int? start, int? end]) → Stream< List< int> > -
Creates a new independent Stream for the contents of this file starting
from
start
and ending atend
. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited