MockMultipartFile class
An uploaded file made in a test, with its content in memory.
Pass it to MockMvc.multipart to send it as a part of a
multipart/form-data request, or straight to a controller method that
takes a MultipartFile. Without an original file name (null),
MockMvc.multipart sends it as a plain part; with application/json
it is then a JSON part for @RequestPart.
// Uploads a cover image to the controller under test.
final cover = MockMultipartFile('cover', 'dune.png', 'image/png', bytes);
await mvc.multipart('/api/covers', files: [cover])
.andExpect(status: 201);
Spring (Java):
MockMultipartFile cover =
new MockMultipartFile("cover", "dune.png", "image/png", bytes);
mockMvc.perform(multipart("/api/covers").file(cover))
.andExpect(status().isCreated());
- Inheritance
-
- Object
- InMemoryMultipartFile
- MockMultipartFile
Constructors
Properties
-
bytes
→ Future<
Uint8List> -
The whole content, loaded into memory; for a large file prefer
openRead or transferTo.
no setterinherited
- contentType → String?
-
The
Content-Typethe client gave the part (image/png), ornullwhen it sent none. It is the client's claim, not checked.finalinherited - hashCode → int
-
The hash code for this object.
no setterinherited
- headers → HttpHeaders
-
All the headers of the part, for anything besides the name and the
type.
finalinherited
- isEmpty → bool
-
Whether the content is empty, which is what a browser sends when no
file was chosen in the form.
no setterinherited
- name → String
-
The name of the form field the file was sent in (
name=of the part), not the file name.finalinherited - originalFilename → String?
-
The file name on the client's machine (
filename=of the part), ornullwhen it sent none. Do not use it as a path as it is: it comes from the client.finalinherited - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- size → int
-
The size of the content, in bytes.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
openRead(
) → Stream< List< int> > -
The content as a stream of chunks, read from the temporary file
without loading it whole; each call starts a new read.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
transferTo(
String path) → Future< void> -
Saves the content as the file at
path, like Spring'stransferTo. A temporary file is moved there when possible (else copied), so call it once, after any other read. Needsdart:io; an InMemoryMultipartFile throws anUnsupportedError.inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited