| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 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 | 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:io'; | 8 import 'dart:io'; |
| 9 import 'dart:math'; | 9 import 'dart:math'; |
| 10 import 'dart:uri'; | 10 import 'dart:uri'; |
| 11 import 'dart:utf'; | 11 import 'dart:utf'; |
| 12 | 12 |
| 13 import 'base_request.dart'; | 13 import 'base_request.dart'; |
| 14 import 'byte_stream.dart'; | 14 import 'byte_stream.dart'; |
| 15 import 'multipart_file.dart'; | 15 import 'multipart_file.dart'; |
| 16 import 'utils.dart'; | 16 import 'utils.dart'; |
| 17 | 17 |
| 18 /// A `multipart/form-data` request. Such a request has both string [fields], | 18 /// A `multipart/form-data` request. Such a request has both string [fields], |
| 19 /// which function as normal form fields, and (potentially streamed) binary | 19 /// which function as normal form fields, and (potentially streamed) binary |
| 20 /// [files]. | 20 /// [files]. |
| 21 /// | 21 /// |
| 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 = new Uri.fromString("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 ContentType('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 { |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 String _boundaryString(int length) { | 166 String _boundaryString(int length) { |
| 167 var prefix = "dart-http-boundary-"; | 167 var prefix = "dart-http-boundary-"; |
| 168 var list = new List<int>.fixedLength(length - prefix.length); | 168 var list = new List<int>.fixedLength(length - prefix.length); |
| 169 for (var i = 0; i < list.length; i++) { | 169 for (var i = 0; i < list.length; i++) { |
| 170 list[i] = _BOUNDARY_CHARACTERS[ | 170 list[i] = _BOUNDARY_CHARACTERS[ |
| 171 _random.nextInt(_BOUNDARY_CHARACTERS.length)]; | 171 _random.nextInt(_BOUNDARY_CHARACTERS.length)]; |
| 172 } | 172 } |
| 173 return "$prefix${new String.fromCharCodes(list)}"; | 173 return "$prefix${new String.fromCharCodes(list)}"; |
| 174 } | 174 } |
| 175 } | 175 } |
| OLD | NEW |