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

Unified Diff: pkg/http/lib/src/multipart_file.dart

Issue 12351006: Change MultipartFile.fromFile to MultipartFile.fromPath in pkg/http. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/http/lib/src/utils.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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,
« no previous file with comments | « no previous file | pkg/http/lib/src/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698