Index: pkg/http/lib/src/multipart_file.dart |
diff --git a/pkg/http/lib/src/multipart_file.dart b/pkg/http/lib/src/multipart_file.dart |
index 50f47047117f9a0164299a4b8a8dd103a24f17b4..07443b80385f4d38ee147e177a9da1470b9f9a12 100644 |
--- a/pkg/http/lib/src/multipart_file.dart |
+++ b/pkg/http/lib/src/multipart_file.dart |
@@ -7,6 +7,8 @@ library multipart_file; |
import 'dart:async'; |
import 'dart:io'; |
+import 'package:pathos/path.dart' as path; |
+ |
import 'byte_stream.dart'; |
import 'utils.dart'; |
@@ -78,14 +80,15 @@ class MultipartFile { |
} |
// TODO(nweiz): Infer the content-type from the filename. |
- /// Creates a new [MultipartFile] from a [File]. |
+ /// Creates a new [MultipartFile] from a path to a file on disk. |
/// |
- /// [filename] defaults to the name of the file on disk. [contentType] |
- /// currently defaults to `application/octet-stream`, but in the future may be |
- /// inferred from [filename]. |
- static Future<MultipartFile> fromFile(String field, File file, |
+ /// [filename] defaults to the basename of [filePath]. [contentType] currently |
+ /// defaults to `application/octet-stream`, but in the future may be inferred |
+ /// from [filename]. |
+ static Future<MultipartFile> fromPath(String field, String filePath, |
{String filename, ContentType contentType}) { |
- if (filename == null) filename = new Path(file.name).filename; |
+ if (filename == null) filename = path.basename(filePath); |
+ var file = new File(filePath); |
return file.length().then((length) { |
var stream = new ByteStream(file.openRead()); |
return new MultipartFile(field, stream, length, |