From 7b75e2f1b0f51f70f22c765719a3c9523b78c7af Mon Sep 17 00:00:00 2001 From: macdonst Date: Wed, 18 Apr 2012 13:56:29 -0400 Subject: [PATCH] CB-539: FileTransfer.download fails when target starts with 'file://' --- .../src/org/apache/cordova/FileTransfer.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/framework/src/org/apache/cordova/FileTransfer.java b/framework/src/org/apache/cordova/FileTransfer.java index 315344b5..a631a055 100644 --- a/framework/src/org/apache/cordova/FileTransfer.java +++ b/framework/src/org/apache/cordova/FileTransfer.java @@ -410,7 +410,7 @@ public class FileTransfer extends Plugin { */ public JSONObject download(String source, String target) throws IOException { try { - File file = new File(target); + File file = getFileFromPath(target); // create needed directories file.getParentFile().mkdirs(); @@ -488,4 +488,17 @@ public class FileTransfer extends Plugin { } } + /** + * Get a File object from the passed in path + * + * @param path + * @return + */ + private File getFileFromPath(String path) { + if (path.startsWith("file://")) { + return new File(path.substring(7)); + } else { + return new File(path); + } + } }