CB-6050: Use instance method on actual file plugin object to get FileEntry to return on download

This commit is contained in:
Ian Clelland 2014-02-18 15:25:01 -05:00
parent 31ac00d3ae
commit 35f80e42ec
2 changed files with 15 additions and 3 deletions

View File

@ -11,7 +11,7 @@
<issue>https://issues.apache.org/jira/browse/CB/component/12320650</issue> <issue>https://issues.apache.org/jira/browse/CB/component/12320650</issue>
<!-- dependency id="org.apache.cordova.file@1" /--> <!-- dependency id="org.apache.cordova.file@1" /-->
<dependency id="org.apache.cordova.file" /> <dependency id="org.apache.cordova.file" version="1.0.1" />
<js-module src="www/FileTransferError.js" name="FileTransferError"> <js-module src="www/FileTransferError.js" name="FileTransferError">
<clobbers target="window.FileTransferError" /> <clobbers target="window.FileTransferError" />

View File

@ -797,9 +797,21 @@ public class FileTransfer extends CordovaPlugin {
Log.d(LOG_TAG, "Saved file: " + target); Log.d(LOG_TAG, "Saved file: " + target);
// create FileEntry object // create FileEntry object
JSONObject fileEntry = FileUtils.getEntry(file); FileUtils filePlugin = (FileUtils)webView.pluginManager.getPlugin("File");
if (filePlugin != null) {
JSONObject fileEntry = filePlugin.getEntryForFile(file);
if (fileEntry != null) {
result = new PluginResult(PluginResult.Status.OK, fileEntry);
} else {
JSONObject error = createFileTransferError(CONNECTION_ERR, source, target, connection);
Log.e(LOG_TAG, "File plugin cannot represent download path");
result = new PluginResult(PluginResult.Status.IO_EXCEPTION, error);
}
} else {
Log.e(LOG_TAG, "File plugin not found; cannot save downloaded file");
result = new PluginResult(PluginResult.Status.ERROR, "File plugin not found; cannot save downloaded file");
}
result = new PluginResult(PluginResult.Status.OK, fileEntry);
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
JSONObject error = createFileTransferError(FILE_NOT_FOUND_ERR, source, target, connection); JSONObject error = createFileTransferError(FILE_NOT_FOUND_ERR, source, target, connection);
Log.e(LOG_TAG, error.toString(), e); Log.e(LOG_TAG, error.toString(), e);