OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 part of dart.io; |
| 6 |
| 7 |
| 8 /** |
| 9 * [:HttpMultipartFormData:] class used for 'upgrading' a [MimeMultipart] by |
| 10 * parsing it as a 'multipart/form-data' part. The following code shows how |
| 11 * it can be used. |
| 12 * |
| 13 * HttpServer server = ...; |
| 14 * server.listen((request) { |
| 15 * String boundary = request.headers.contentType.parameters['boundary']; |
| 16 * request |
| 17 * .transform(new MimeMultipartTransformer(boundary)) |
| 18 * .map(HttpMultipartFormData.parse) |
| 19 * .map((HttpMultipartFormData formData) { |
| 20 * // form data object available here. |
| 21 * }); |
| 22 * |
| 23 * [:HttpMultipartFormData:] is a Stream, serving either bytes or decoded |
| 24 * Strings. Use [isText] or [isBinary] to see what type of data is provided. |
| 25 */ |
| 26 abstract class HttpMultipartFormData implements Stream { |
| 27 /** |
| 28 * The parsed [:Content-Type:] header of the [:HttpMultipartFormData:]. |
| 29 * Returns [:null:] if not present. |
| 30 */ |
| 31 ContentType get contentType; |
| 32 |
| 33 /** |
| 34 * The parsed [:Content-Disposition:] header of the [:HttpMultipartFormData:]. |
| 35 * This field is always present. Use this to extract e.g. name(form field |
| 36 * name)and filename (client provided name of uploaded file) parameters. |
| 37 */ |
| 38 HeaderValue get contentDisposition; |
| 39 |
| 40 /** |
| 41 * The parsed [:Content-Transfer-Encoding:] header of the |
| 42 * [:HttpMultipartFormData:]. This field is used to determine how to decode |
| 43 * the data. Returns [:null:] if not present. |
| 44 */ |
| 45 HeaderValue get contentTransferEncoding; |
| 46 |
| 47 /** |
| 48 * Returns [:true:] if the data is decoded as [String]. |
| 49 */ |
| 50 bool get isText; |
| 51 |
| 52 /** |
| 53 * Returns [:true:] if the data is raw bytes. |
| 54 */ |
| 55 bool get isBinary; |
| 56 |
| 57 /** |
| 58 * Returns the value for the header named [name]. If there |
| 59 * is no header with the provided name, [:null:] will be returned. |
| 60 * |
| 61 * Use this method to index other headers available in the original |
| 62 * [MimeMultipart]. |
| 63 */ |
| 64 String value(String name); |
| 65 |
| 66 /** |
| 67 * Parse a [MimeMultipart] and return a [HttpMultipartFormData]. If the |
| 68 * [:Content-Disposition:] header is missing or invalid, a [HttpException] is |
| 69 * thrown. |
| 70 */ |
| 71 static HttpMultipartFormData parse(MimeMultipart multipart) |
| 72 => _HttpMultipartFormData.parse(multipart); |
| 73 } |
OLD | NEW |