Read file from usb-drive


#1

Hi

Can anyone help me please.
In my Ionic1 App, I would like to open a pdf-document which is located on an usb-drive which is connected to the mobile device.

How would I achieve this ?

Kind Regards
Joost


#2

use file plugin and specify path of USB device as external memory to manage any type of file.


#3

Would you have a code sample to achieve this ?


#4

just read the document mentioned in bellow link. The directory structure of Android device is also mentioned in it. You certainly can do it with proper reading.

http://ngcordova.com/docs/plugins/file/

or


#5

Hi

Via the properties of the cordova-file-plugin you cannot access the usb-drive.
I hope someone else can help me out.

How can I access a directory / file on the usb-drive which is connected to the device ?


#6

The root for the files on USB drive(External Source) will be / as per document of plugin.


#7

So how would you change following code to be able to read the contents of the usb-drive ?

    vm.leesDir = function leesDir(path) {
        $window.resolveLocalFileSystemURL(
            cordova.file.externalRootDirectory,
            function (dirEntry) {

                var dirReader = dirEntry.createReader();

                dirReader.readEntries(
                    function (entries) {
                        console.dir(entries); // directory entries
                    },
                    function (err) {
                        console.log(err);
                    }
                );

            },
            function (err) {
                console.log(err);
            }
        );
    };

#8

How are you calling this function


#9

It was originally :

vm.leesDir = function leesDir(path) {
$window.resolveLocalFileSystemURL(
path,
function (dirEntry) {

            var dirReader = dirEntry.createReader();

            dirReader.readEntries(
                function (entries) {
                    console.dir(entries); // directory entries
                },
                function (err) {
                    console.log(err);
                }
            );

        },
        function (err) {
            console.log(err);
        }
    );
};

and calling via

leesDir(’/storage/’);
or
leesDir(‘file:///storage/’);

When I connect the USB-drive, the files are located on

/storage/02DD-A5BD/

So when I call leesDir(’/storage’), I would like to get a listing of ‘/02DD-A5BD’ with it’s files and subfolders.
However this doesn’t seem to work.


#10

Try removing the memory card inserted in the phone


#11

There is no SdCard inserted at this moment.