ContentDisposition class final
The value of a Content-Disposition header: whether a body is shown
by the browser (inline), saved as a file (attachment) or is one
field of a multipart form (form-data), with the file or field name.
A controller sets it on a download so that the browser saves the file
under a chosen name; each part of a multipart body has a form-data
one. A non-ASCII file name is written as filename* (RFC 5987, UTF-8)
and read back from it, so any name is safe.
// A download the browser saves as report.pdf instead of showing it.
@GetMapping('/reports/{id}.pdf')
ResponseEntity<Uint8List> report(@PathVariable() String id) {
final headers = HttpHeaders()
..contentType = 'application/pdf'
..contentDisposition =
const ContentDisposition.attachment(filename: 'report.pdf');
return ResponseEntity(200, body: reports.pdf(id), headers: headers);
}
Spring (Java):
headers.setContentDisposition(
ContentDisposition.attachment().filename("report.pdf").build());
headers.getContentDisposition().getFilename();
Constructors
- ContentDisposition(String type, {String? name, String? filename})
-
A disposition of any
type, with an optionalnameandfilename; the named constructors cover the three usual types.const - ContentDisposition.attachment({String? filename})
-
attachment: the browser saves the body as a file, namedfilenamewhen given.const - ContentDisposition.formData({required String name, String? filename})
-
form-data: the part of a multipart form for the fieldname;filenamemakes it a file.const - ContentDisposition.inline({String? filename})
-
inline: the browser shows the body, as it does without the header;filenameis the name offered if the user saves it.const
Properties
- filename → String?
-
The file name, from
filename*(decoded) orfilename;nullwhen there is none.final - hashCode → int
-
The hash code for this object.
no setteroverride
- isAttachment → bool
-
Whether the type is
attachment.no setter - isFormData → bool
-
Whether the type is
form-data.no setter - isInline → bool
-
Whether the type is
inline.no setter - name → String?
-
The
nameparameter, the form field of aform-datapart;nullotherwise.final - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- type → String
-
The disposition type:
attachment,inline,form-data, or another; lower case when parsed.final
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
The header value, such as
attachment; filename="report.pdf". Quotes and backslashes in the names are escaped; a file name that is not printable ASCII is written asfilename*=UTF-8''....override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
override
Static Methods
-
parse(
String value) → ContentDisposition -
Reads a header value such as
attachment; filename="report.pdf", like Spring'sContentDisposition.parse. The type is lower-cased, quotes and backslash escapes are removed,filename*wins overfilename, and other parameters are ignored. Throws anArgumentErrorwhen the value has no type.