Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GetFile Cordova 3.4.0 err.code 1000

I try to GetFile with cordova 3.4.0 :

    FileManager.prototype.ReadAsTextFromFile = function (fileName, readDataCallBack) {
    var that = this;
    try {
        window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) {
            fileSystem.root.getFile(fileName, {create: false}, 
                function (fileEntry) {
                    fileEntry.file(
                        function (file){
                            var reader = new FileReader();                             
                            reader.onloadend = readDataCallBack;
                            reader.readAsText(file);
                        }                   
                    , function(err){alert('ReadFile' + " fail: " + err.code);});
                }
            , function(err){alert('GetFile' + " fail: " + err.code);});
        }, function(err){alert('FileSystem' + " fail: " + err.code);});
    } catch (e) {
        logError(e);
    }
}       

but obtain the err.code 1000 on the call getfile.

the file name is :

var fileName = "/scard/" + reliefsSubfolderName + reliefname 
               + String.fromCharCode(47) + reliefsManifestFileName;

/scard/my_dir_on_card/my_file_name.drd (drd is my extension but is a text file)

May I know what is the correct way to achieve my objective?

like image 447
user3454369 Avatar asked Mar 21 '23 03:03

user3454369


1 Answers

I guess you need to omit the leading "/" from your fileName.
Most possible cause of Error code 1000 is non-existent path file while geting a reference through getFile with create option as false

fileSystem.root.getFile(fileName, {create: false},...

You may try to inspect the full file path before invoking getFile and see if it is valid. Your path should not contain multiple consecutive "/" other than initial protocol. e.g cdvfile://localhost/persistent/scard.....

console.log(fileSystem.root.toURL() + fileName);
like image 52
Amitesh Avatar answered Apr 01 '23 20:04

Amitesh