0

我正在尝试通过 resumable.js 从 Android 文件系统上传文件。我设置了我的 Resumable-Object 并使用 .fileAdd 添加我从本地文件系统请求的文件。根据文档,如果添加了文件,则应触发事件“fileAdded”。但事实并非如此。那么,是否可以从文件系统添加文件,或者我是否必须使用“.assignBrowse”方法从 UI 添加文件?

这是我所做的:

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

1 回答 1

0

Boah 很简单,我只需要切换resumable.on(...)and的顺序resumable.addFile(...)。现在看起来像这样:

            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'));
于 2014-01-29T09:28:14.713 回答