简体   繁体   中英

Cordova getFile and external SD card

$window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);

function gotFS(fs) {
     // case 1
     fs.root.getFile('/storage/emulated/0/VIDEO0048.mp4', null, ok, fail);
     //case 2
     fs.root.getFile('/storage/ext_sd/VIDEO0048.mp4', null, ok, fail);

}

In the above code using the Cordova file plugin v1.3.3 on Android, case 1 works and case 2 doesn't. For case 2 it reports error 1000. I know both files exist, one in internal storage and one on the SD card and I have READ_EXTERNAL_STORAGE permissions set in the manifest. Has anyone used the Cordova file plugin to access files on the SD card this way and got it working?

Here is the answer to my own question in case it helps anyone else.

To get this to work I upgraded to the 2.1.0 version of cordova-plugin-file and instead of using getFile (that no longer takes an absolute path) I used $window.resolveLocalFileSystemURL to get a fileEntry which worked for both internal and SD card paths. The only wrinkle was that I had to prepend "file://" to my path so that it looked like this "file:///storage/ext_sd/VIDEO0048.mp4" when passed into resolveLocalFileSystemURL.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM