问题
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