账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    FileSystemAPI沙盒
    43
    0

    调用FileSystemAPI在本地沙盒中创建文件,代码如下:

     readerFile:function(file,callBack){
                fileSystemObj.fs.root.getFile(file, {create: true}, function(fileEntry) {   
                    console.log(3);
                    fileEntry.file(function(file) {
                        console.log(4);
                        var reader = new FileReader();
                        reader.onloadend = function() {
                            typeof callBack == 'function' && callBack.call(fileEntry,this.result);
                        };
                        reader.readAsText(file);
                    }, fileSystemObj.errorHandler);
                }, fileSystemObj.errorHandler);
            },
            initialize  : function(filename) {
                window.requestFileSystem(TEMPORARY, this.size, function (fs) {
                    fileSystemObj.fs = fs;
                    fileSystemObj.readerFile(filename,function(text){
                        console.log(text);
                    });
                })
            }
        };
        
         if(window.requestFileSystem) {
            navigator.webkitTemporaryStorage.queryUsageAndQuota(function (usage, quota) {
                if (!quota) {
                    console.log(1);
                    navigator.webkitTemporaryStorage.requestQuota(fileSystemObj.size, function () {
                        fileSystemObj.initialize();
                    }, fileSystemObj.errorHandler);
                }else{
                    console.log(2)
                    fileSystemObj.initialize();
                }
            });
        }else{
            alert("请使用chrome浏览器浏览!");
        }
    }

    控制台下报错:

    2
    sandbox_fileSystem.js:23 SecurityError
    DOMException: It was determined that certain files are unsafe for access within a Web application, or that too many calls are being made on file resources.

    请问各位码友如何解决?

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 原來無話可說 普通会员 1楼

      FileSystemAPI沙盒是一种虚拟环境,用于隔离不同的文件系统API之间的依赖关系,提高代码的可测试性和可重用性。它通常在测试环境中使用,以便在不同的测试用例之间切换。

      在开发过程中,开发人员通常会在代码中创建一个内置的FileSystemAPI沙盒。然后,他们可以在这个沙盒中测试不同的文件系统API,并在测试完成后将沙盒中的文件系统API设置为默认的。

      这种沙盒设计的优点是可以减少对原生文件系统API的依赖,从而提高代码的可测试性和可重用性。同时,也可以提高代码的可移植性,因为沙盒可以在不同的环境中重用。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部