fileAdded-Event not fired

759 views Asked by At

I'm trying to upload a file from Android filesystem via resumable.js. I set up my Resumable-Object and use .fileAdd to add the file I requested from the local filesystem. According to the Documentation the event 'fileAdded' should be fired if a file was added. But it isn't. So, is it possible at all to add a file from file system or do I have to use the '.assignBrowse'-Method to add a file from UI ?

Here's what I did:

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem){

    var resumable = new Resumable({
        target: 'v16/chunk',
        chunkSize: 1024 * 128
    });

    fileSystem.root.getFile(theFileName, {create: false}, function(fileEntry){

        resumable.addFile(fileEntry); // File from file system
        console.log("manual add");

        resumable.files.forEach(function(item){
            // log the added files
            console.log(item.fileName);
            console.log(item.relativePath); // undefined
            console.log(item.size); // NaN
        });

        console.log("Size  " + resumable.getSize()); // NaN

        resumable.on('fileAdded', function(file){
            console.log("File Added"); // Shouldn't this be called?
            resumable.upload();
        });

    }, that.get('fail'));
}, that.get('fail'));
1

There are 1 answers

0
matthisb On BEST ANSWER

Boah simple as it is, i just have to switch the order of resumable.on(...) and resumable.addFile(...). Now it looks like this:

            window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem){

                        var resumable = new Resumable({
                            target:'v16/chunk',
                            chunkSize: 1024 * 128
                        });

                        fileSystem.root.getFile(theFileName, {create: false}, function(fileEntry){

                            resumable.on('fileAdded', function(file){
                                console.log("File Added");
                                resumable.upload();
                            });


                            resumable.addFile(fileEntry);

                            resumable.files.forEach(function(item){
                                console.log(item.fileName);
                                console.log(item.relativePath);
                                console.log(item.size);
                            });

                            console.log("Size  " + resumable.getSize());


                        }, that.get('fail'));

            }, that.get('fail'));