[ 
https://issues.apache.org/jira/browse/CB-6394?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14017916#comment-14017916
 ] 

Kelvin Dart commented on CB-6394:
---------------------------------

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():
`var fileTransfer = new FileTransfer();

fileTransfer.download(
    'http://myurl.com/file.pdf',
    entry.toURL(),
    function () { /* file downloaded */ },
    function (err) { /* console.log(error) */ }
);`

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:

`- (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;
}`

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

> Merge file-system-roots plugin functionality into core file plugin
> ------------------------------------------------------------------
>
>                 Key: CB-6394
>                 URL: https://issues.apache.org/jira/browse/CB-6394
>             Project: Apache Cordova
>          Issue Type: Improvement
>          Components: Plugin File
>            Reporter: Ian Clelland
>            Assignee: Ian Clelland
>
> [Relevant mailing list thread|http://markmail.org/thread/iarsjqjynd7kpcyk]
> The extra file system roots are compelling enough that they should be part of 
> the core File plugin (on Android and iOS right now -- other platforms should 
> also be able to add their own roots)
> If we enable the root file system, then this should enable developers to 
> access files created by other plugins, (see: Media-Capture,) regardless of 
> where they stored on the device.



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to