Ian Clelland created CB-6881: -------------------------------- Summary: FileTransfer passes file:/// URLs to File when cdvfile:// is expected Key: CB-6881 URL: https://issues.apache.org/jira/browse/CB-6881 Project: Apache Cordova Issue Type: Bug Components: Plugin File, Plugin File Transfer Reporter: Ian Clelland Assignee: Ian Clelland
>From CB-6394 Comment: Hi Ian, I have just been debugging an issue I was having with the FileTransfer code which was causing me a problem in Cordova 3.5.0. In previous versions, I was using code along the following lines, where I would be using entry.toURL(): {code} var fileTransfer = new FileTransfer(); fileTransfer.download( 'http://myurl.com/file.pdf', entry.toURL(), function () { /* file downloaded */ } , function (err) { /* console.log(error) */ } ); {code} But in 3.5.0 this did not seem to work - when I looked at the File plugin (on iOS), particularly CDVFile, there's the following method which was the reason why: {code} - (NSString *)filesystemNameForLocalURI:(NSURL *)uri { if ([[uri scheme] isEqualToString:kCDVFilesystemURLPrefix] && [[uri host] isEqualToString:@"localhost"]) { NSArray *pathComponents = [uri pathComponents]; if (pathComponents != nil && pathComponents.count > 1) { return [pathComponents objectAtIndex:1]; } } else if ([[uri scheme] isEqualToString:kCDVAssetsLibraryScheme]) { return @"assets-library"; } return nil; } {code} Which is called within FileTransfer, when downloading a file, and uses the {{target}} parameter to resolve to the File System to store your download. That's fine, but in the documentation here: https://github.com/apache/cordova-plugin-file/blob/master/doc/index.md, it recommends using toURL() - however, when I use this on a File or Directory Entry, I receive a path string beginning with 'file:///'. So when Cordova attempts to resolve this location, using {{filesystemNameForLocalURI}} to store the downloaded file, it's never going to be able to create the target location, since the scheme never matches those two checks ('cdvfile' or 'assets library'). In order to get around the issue, I had to use toInternalURL() instead, which return my entry path as a cdvfile. Thus, I wondered whether the documentation is wrong? Either way, I'm a little confused! I hope my query makes sense. Many thanks, Kelvin -- This message was sent by Atlassian JIRA (v6.2#6252)