UploadFile class
One file in a multipart upload.
Two constructors, because the two platforms disagree about what a file is: UploadFile.fromPath for mobile and desktop, UploadFile.fromBytes for web (where a picked file has no filesystem path) and for anything already held in memory.
await api.upload(
endpoint: '/documents',
fields: {'title': 'Q3 report', 'visibility': 'team'},
files: [
UploadFile.fromPath(field: 'document', path: pickedFile.path),
UploadFile.fromBytes(
field: 'thumbnail',
bytes: thumbnailBytes,
filename: 'thumb.png',
),
],
onSendProgress: (sent, total) => progress.value = sent / total,
);
Constructors
-
UploadFile.fromBytes({required String field, required List<
int> bytes, required String filename, String? contentType}) -
A file already in memory. Works on every platform, including web.
const
- UploadFile.fromPath({required String field, required String path, String? filename, String? contentType})
-
A file on disk. Not available on web — use UploadFile.fromBytes there.
const
Properties
-
bytes
→ List<
int> ? -
In-memory contents. Mutually exclusive with path.
final
- contentType → String?
-
MIME type, e.g.
image/png.final - field → String
-
The multipart field name the server expects, e.g.
avatar.final - filename → String?
-
Name sent to the server. Required for UploadFile.fromBytes — there is
no path to derive one from. Defaults to the basename of path
otherwise.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- path → String?
-
Filesystem path. Mutually exclusive with bytes.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toMultipartFile(
) → Future< MultipartFile> - Converts to the Dio representation. Reads the file from disk when this was built with UploadFile.fromPath.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited