UploadedFile class base

Represents an uploaded file parsed from an incoming HTTP request.

UploadedFile provides convenient access to file metadata, raw bytes, string content, type inspection helpers, disk persistence methods, HTTP response streaming, and S3 upload support.

Instances are typically created internally while parsing multipart form data, but they can also be constructed directly from bytes.

Example:

final file = UploadedFile.fromBytes(
  filename: 'avatar.png',
  bytes: Uint8List.fromList([1, 2, 3]),
  contentType: 'image/png',
);

print(file.filename); // avatar.png
print(file.isImage); // true

Constructors

UploadedFile.empty()
Creates an empty placeholder file.
factory
UploadedFile.fromBytes({required String filename, required Uint8List bytes, required String contentType})
Creates an uploaded file from an in-memory byte buffer.

Properties

bytes Future<Uint8List>
Returns the file contents as raw bytes.
no setter
contentType String
MIME content type associated with the uploaded file.
final
extension String
Returns the lowercase file extension without a leading dot.
no setter
filename String
Original filename supplied by the client.
final
hashCode int
The hash code for this object.
no setterinherited
isAudio bool
Returns true when the file appears to be an audio file.
no setter
isImage bool
Returns true when the file appears to be an image file.
no setter
isLengthKnown bool
Returns true when the file length is already known without recomputing it.
no setter
isValid bool
Returns true when the file has a non-empty filename.
no setter
isVideo bool
Returns true when the file appears to be a video file.
no setter
length Future<int>
Returns the byte length of the file.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
string Future<String>
Returns the file contents decoded as UTF-8 text.
no setter

Methods

copyWith({String? filename, String? contentType}) Future<UploadedFile>
Returns a copy of this file with updated metadata.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
save(String path) Future<File>
Saves the file to the provided filesystem path.
saveToPrivateDir(String subDir, {bool autoName = true}) Future<File>
Saves the file into a subdirectory of the private storage path.
saveToPublicDir(String subDir, {bool autoName = true}) Future<File>
Saves the file into a subdirectory of the public storage path.
streamTo(StreamSink<List<int>> sink) Future<void>
Streams the file bytes into a StreamSink.
streamToResponse(HttpRequest request, {bool handleRange = true}) Future<void>
Streams this file to the current HTTP response.
streamToS3({S3Acl acl = .private, bool autoName = true}) Future<String?>
Uploads the file to S3 and returns the stored object key.
toJson() Future<Map<String, dynamic>>
Returns file metadata as a JSON-compatible map.
toString() String
Returns a developer-friendly string representation of the file.
override

Operators

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