Как использовать webkitRequestFileSystem в файле: протокол
В соответствии сИзучение API файловой системы в
Поддержка браузера и ограничения хранения
Вам может понадобиться--allow-file-access-from-files
флаг, если вы отлаживаете свое приложение изfile://
, Не использование этих флагов приведет кSECURITY_ERR
или жеQUOTA_EXCEEDED_ERR
FileError.
Запущен хром с--allow-file-access-from-files
, --unlimited-storage
и, возможно, не рекомендуется--unlimited-quota-for-files
; также--unsafely-treat-insecure-origin-as-secure=file:///path/to/directory/*
с--user-data-dir=/path/to/directory
задавать.
Интересно, что при открытии хрома отображается уведомление
Вы используете неподдерживаемый флаг командной строки:--unsafely-treat-insecure-origin-as-secure
, Стабильность и безопасность пострадают.
Есть другие флаги, которые не указаны, которые можно использовать; проигнорировал уведомление, так как все еще был в состоянии установить и получитьlocalStorage
вfile:
протокол, особенно файлы вfile:///path/to/directory/*
, хоть
navigator.webkitTemporaryStorage.requestQuota(1024*1024, function(grantedBytes) {
console.log(grantedBytes)
}, errorHandler);
войти0
, гдеerrorHandler
является
function errorHandler(e) {
console.log(e)
}
Также
function writeFile(fs) {
fs.root.getFile("file.txt", {create: true}, function(fileEntry) {
fileEntry.createWriter(function(fileWriter) {
fileWriter.onwriteend = function(e) {
// call `readFile`
window.requestFileSystem(window.TEMPORARY, 1024*1024, readFile, errorHandler);
};
fileWriter.onerror = errorHandler;
var blob = new Blob(["abc"], {type: "text/plain"});
fileWriter.write(blob);
}, errorHandler);
}, errorHandler);
}
window.requestFileSystem(window.TEMPORARY, 1024*1024, writeFile, errorHandler);
function readFile(fs) {
fs.root.getFile("file.txt", {}, function(fileEntry) {
fileEntry.file(function(file) {
var reader = new FileReader();
reader.onloadend = function(e) {
console.log(e.target.result)
};
reader.readAsText(file);
}, errorHandler);
}, errorHandler);
}
войти
FileError {code: 7, name: "InvalidStateError", message: "An operation that depends on state cached in an in…he state had changed since it was read from disk."}
code:7
message:"An operation that depends on state cached in an interface object was made but the state had changed since it was read from disk."
name:"InvalidStateError"
__proto__:DOMError
Вопрос: Какие изменения необходимы для флагов запуска, обходных путей или других подходов, которые позволили бы использоватьwebkitRequestFileSystem
вfile:
протокол?