OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library multipart_request; | 5 library multipart_request; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:convert'; | 8 import 'dart:convert'; |
9 import 'dart:math'; | 9 import 'dart:math'; |
10 | 10 |
(...skipping 11 matching lines...) Expand all Loading... |
22 /// This request automatically sets the Content-Type header to | 22 /// This request automatically sets the Content-Type header to |
23 /// `multipart/form-data` and the Content-Transfer-Encoding header to `binary`. | 23 /// `multipart/form-data` and the Content-Transfer-Encoding header to `binary`. |
24 /// These values will override any values set by the user. | 24 /// These values will override any values set by the user. |
25 /// | 25 /// |
26 /// var uri = Uri.parse("http://pub.dartlang.org/packages/create"); | 26 /// var uri = Uri.parse("http://pub.dartlang.org/packages/create"); |
27 /// var request = new http.MultipartRequest("POST", url); | 27 /// var request = new http.MultipartRequest("POST", url); |
28 /// request.fields['user'] = 'nweiz@google.com'; | 28 /// request.fields['user'] = 'nweiz@google.com'; |
29 /// request.files.add(new http.MultipartFile.fromFile( | 29 /// request.files.add(new http.MultipartFile.fromFile( |
30 /// 'package', | 30 /// 'package', |
31 /// new File('build/package.tar.gz'), | 31 /// new File('build/package.tar.gz'), |
32 /// contentType: new ContentType('application', 'x-tar')); | 32 /// contentType: new MediaType('application', 'x-tar')); |
33 /// request.send().then((response) { | 33 /// request.send().then((response) { |
34 /// if (response.statusCode == 200) print("Uploaded!"); | 34 /// if (response.statusCode == 200) print("Uploaded!"); |
35 /// }); | 35 /// }); |
36 class MultipartRequest extends BaseRequest { | 36 class MultipartRequest extends BaseRequest { |
37 /// The total length of the multipart boundaries used when building the | 37 /// The total length of the multipart boundaries used when building the |
38 /// request body. According to http://tools.ietf.org/html/rfc1341.html, this | 38 /// request body. According to http://tools.ietf.org/html/rfc1341.html, this |
39 /// can't be longer than 70. | 39 /// can't be longer than 70. |
40 static const int _BOUNDARY_LENGTH = 70; | 40 static const int _BOUNDARY_LENGTH = 70; |
41 | 41 |
42 static final Random _random = new Random(); | 42 static final Random _random = new Random(); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 /// Returns a randomly-generated multipart boundary string | 167 /// Returns a randomly-generated multipart boundary string |
168 String _boundaryString() { | 168 String _boundaryString() { |
169 var prefix = "dart-http-boundary-"; | 169 var prefix = "dart-http-boundary-"; |
170 var list = new List<int>.generate(_BOUNDARY_LENGTH - prefix.length, | 170 var list = new List<int>.generate(_BOUNDARY_LENGTH - prefix.length, |
171 (index) => | 171 (index) => |
172 _BOUNDARY_CHARACTERS[_random.nextInt(_BOUNDARY_CHARACTERS.length)], | 172 _BOUNDARY_CHARACTERS[_random.nextInt(_BOUNDARY_CHARACTERS.length)], |
173 growable: false); | 173 growable: false); |
174 return "$prefix${new String.fromCharCodes(list)}"; | 174 return "$prefix${new String.fromCharCodes(list)}"; |
175 } | 175 } |
176 } | 176 } |
OLD | NEW |