简体   繁体   中英

fileAdded-Event not fired

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'));

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'));

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