Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(244)

Side by Side Diff: pkg/http/lib/src/multipart_file.dart

Issue 11783009: Big merge from experimental to bleeding edge. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/http/lib/src/mock_client.dart ('k') | pkg/http/lib/src/multipart_request.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_file; 5 library multipart_file;
6 6
7 import 'dart:io'; 7 import 'dart:io';
8 8
9 import 'utils.dart'; 9 import 'utils.dart';
10 10
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 78
79 // TODO(nweiz): Infer the content-type from the filename. 79 // TODO(nweiz): Infer the content-type from the filename.
80 /// Creates a new [MultipartFile] from a [File]. 80 /// Creates a new [MultipartFile] from a [File].
81 /// 81 ///
82 /// [filename] defaults to the name of the file on disk. [contentType] 82 /// [filename] defaults to the name of the file on disk. [contentType]
83 /// currently defaults to `application/octet-stream`, but in the future may be 83 /// currently defaults to `application/octet-stream`, but in the future may be
84 /// inferred from [filename]. 84 /// inferred from [filename].
85 static Future<MultipartFile> fromFile(String field, File file, 85 static Future<MultipartFile> fromFile(String field, File file,
86 {String filename, ContentType contentType}) { 86 {String filename, ContentType contentType}) {
87 if (filename == null) filename = new Path(file.name).filename; 87 if (filename == null) filename = new Path(file.name).filename;
88 return file.length().transform((length) { 88 return file.length().then((length) {
89 return new MultipartFile(field, file.openInputStream(), length, 89 return new MultipartFile(field, file.openInputStream(), length,
90 filename: filename, 90 filename: filename,
91 contentType: contentType); 91 contentType: contentType);
92 }); 92 });
93 } 93 }
94 94
95 // Finalizes the file in preparation for it being sent as part of a 95 // Finalizes the file in preparation for it being sent as part of a
96 // [MultipartRequest]. This returns an [InputStream] that should emit the body 96 // [MultipartRequest]. This returns an [InputStream] that should emit the body
97 // of the file. The stream may be closed to indicate an empty file. 97 // of the file. The stream may be closed to indicate an empty file.
98 InputStream finalize() { 98 InputStream finalize() {
99 if (isFinalized) { 99 if (isFinalized) {
100 throw new StateError("Can't finalize a finalized MultipartFile."); 100 throw new StateError("Can't finalize a finalized MultipartFile.");
101 } 101 }
102 _isFinalized = true; 102 _isFinalized = true;
103 return _stream; 103 return _stream;
104 } 104 }
105 } 105 }
OLDNEW
« no previous file with comments | « pkg/http/lib/src/mock_client.dart ('k') | pkg/http/lib/src/multipart_request.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698