Chrome App Persistent Filesystem Storage not reliable

徘徊边缘 提交于 2019-12-11 18:04:42

问题


I am having issues with my google chrome app and filestorage.

The app is run online and gathers files to store offline so that it should be able to function properly offline later. It does this for the most part but sometimes but rarely after a computer restart or restarting the browser it seems to be missing the files in filesystem...

I guess my question is, how do i ensure that Persistent storage remains persistent?

Edit:

Code

Request filesystem

window.requestFileSystem  = window.requestFileSystem || window.webkitRequestFileSystem;
window.requestFileSystem(
window.PERSISTENT, 200*1024*1024,
    function(filesystem) {
        directory.fs = filesystem;
        //Start Application
    },
    filesystemerrorHandler
);

Save a File from remote to local filesystem

var xhr = new XMLHttpRequest();
xhr.open('GET', fileurl, true);
xhr.responseType = 'blob';
xhr.send();
xhr.onload = function(e) {
    if (this.status == 200) {
        var blob = new Blob([this.response], {type: blobtype});
        directory.fs.root.getFile(name, {create: true}, function(fileEntry) {
            fileEntry.createWriter(function(writer) {
                writer.onwrite = function(e) {};
                writer.onerror = function(e) { console.log("error"); console.log(e); };
                var blob = new Blob([xhr.response], {type: blobtype});
                writer.write(blob);
                var url = fileEntry.toURL();
                if ( typeof(callback) == 'function' ) {
                    //Save url to indexeddb for recall later
                    //Returns format of: filesystem:chrome-extension://nlipipdnicabdffnohdhhliiajoonmgm/persistent/xxxxxxxxxxxx.png
                    callback(url);    
                }
            }, filewriteerrorHandler2);
        }, filewriteerrorHandler);
    }
    else {
        if ( typeof(callback) == 'function' ) callback(false);
    }
};

Recalling the downloaded file example

<img src="filesystem:chrome-extension://nlipipdnicabdffnohdhhliiajoonmgm/persistent/xxxxxxxxxxxx.png">

Now for the most part this will work. However, sometimes, if the computer has been restarted or the browser restarted. If I use the app again the image will not show, this is giving me the impression that the filesystem has been cleared for this app.

What steps, or what area should I be looking at to prevent this from happening?

Thanks.


回答1:


Increasing the amount of bytes allocated to the app worked. I was storing more than i was allocating.

window.requestFileSystem  = window.requestFileSystem || window.webkitRequestFileSystem;
window.requestFileSystem(
    window.PERSISTENT, 200*1024*1024,    <====
    function(filesystem) {
        directory.fs = filesystem;
        //Start Application
    },
    filesystemerrorHandler
);


来源:https://stackoverflow.com/questions/19178276/chrome-app-persistent-filesystem-storage-not-reliable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!