UploadedFile class final

A file sent in a multipart/form-data request (Laravel's Illuminate\Http\UploadedFile).

The upload is streamed to a temporary file while the request is parsed (deleted once the response is sent); its first bytes are kept to detect the real type. clientName and clientMimeType come from the client and must not be trusted; mimeType and extension are read from the content, as Laravel's getMimeType() and guessExtension() are.

Constructors

UploadedFile.fromBytes(List<int> bytes, {required String name, String? mimeType})
An upload held in memory (tests, generated files).
factory
UploadedFile.temporary({required String path, required String clientName, required String clientMimeType, required int size, required List<int> header})
An upload that was streamed to path (used by the multipart parser).
factory

Properties

clientExtension → String
The extension of clientName, lower-cased, without the dot (getClientOriginalExtension).
no setter
clientMimeType → String
The MIME type the client claimed (getClientMimeType).
final
clientName → String
The file name the client sent (getClientOriginalName).
final
extension → String?
The extension that matches mimeType (guessExtension), or null.
no setter
hashCode → int
The hash code for this object.
no setterinherited
mimeType → String
The type detected from the content (getMimeType), never from the name: application/octet-stream when it cannot be recognised.
no setter
path → String?
Temporary file holding the content (null for in-memory uploads).
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
size → int
Size in bytes.
final

Methods

bytes() → Future<Uint8List>
The whole content.
delete() → Future<void>
Deletes the temporary file (done automatically after the response).
hashName([String? directory]) → String
A random 40-character name with the detected extension (hashName).
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
openRead() → Stream<List<int>>
The content as a stream.
readAsBytesSync() → Uint8List
The whole content, read synchronously (fakes and small files).
store(String directory, {String? disk}) → Future<String>
Stores the file under directory with a hashName on disk (the default disk when null) and returns its path (store).
storeAs(String directory, String name, {String? disk}) → Future<String>
Stores the file as directory/name on disk and returns the path (storeAs). name is not checked: never pass clientName unchanged.
text() → Future<String>
The content as UTF-8 text (getContent).
toString() → String
A string representation of this object.
override

Operators

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

Constants

fake → const UploadedFileFactory
Fake uploads for tests (UploadedFile::fake()).
headerLength → const int
How many leading bytes are kept for type detection.