MultipartFile class

A file to be uploaded as part of a MultipartRequest. This doesn't need to correspond to a physical file.

MultipartFile is based on stream, and a stream can be read only once, so the same MultipartFile can't be read multiple times.

Constructors

MultipartFile(Stream<List<int>> stream, int length, {String? filename, DioMediaType? contentType, Map<String, List<String>>? headers})
Creates a new MultipartFile from a chunked Stream of bytes. The length of the file in bytes must be known in advance. If it's not, read the data from the stream and use MultipartFile.fromBytes instead.
MultipartFile.fromBytes(List<int> value, {String? filename, DioMediaType? contentType, Map<String, List<String>>? headers})
Creates a new MultipartFile from a byte array.
factory
MultipartFile.fromStream(Stream<List<int>> data(), int length, {String? filename, DioMediaType? contentType, Map<String, List<String>>? headers})
Creates a new MultipartFile from a chunked Stream of bytes. The length of the file in bytes must be known in advance. If it's not, read the data from the stream and use MultipartFile.fromBytes instead.
MultipartFile.fromString(String value, {String? filename, DioMediaType? contentType, Map<String, List<String>>? headers})
Creates a new MultipartFile from a string.
factory

Properties

contentType DioMediaType?
The content-type of the file. Defaults to application/octet-stream.
final
filename String?
The basename of the file. May be null.
final
hashCode int
The hash code for this object.
no setterinherited
headers Map<String, List<String>>?
The additional headers the file has. May be null.
final
isFinalized bool
Whether finalize has been called.
no setter
length int
The size of the file in bytes. This must be known in advance, even if this file is created from a ByteStream.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

clone() MultipartFile
Clone MultipartFile, returning a new instance of the same object. This is useful if your request failed and you wish to retry it, such as an unauthorized exception can be solved by refreshing the token.
finalize() Stream<Uint8List>
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

fromFile(String filePath, {String? filename, DioMediaType? contentType, Map<String, List<String>>? headers}) Future<MultipartFile>
Creates a new MultipartFile from a path to a file on disk.
fromFileSync(String filePath, {String? filename, DioMediaType? contentType, Map<String, List<String>>? headers}) MultipartFile