Como usar o webkitRequestFileSystem no arquivo: protocol
De acordo comExplorando as APIs do FileSystem às
Suporte ao navegador e limitações de armazenamento
Você pode precisar do--allow-file-access-from-files
sinalizar se você estiver depurando seu aplicativo defile://
. Não usar esses sinalizadores resultará em umaSECURITY_ERR
ouQUOTA_EXCEEDED_ERR
Erro de arquivo.
Cromo lançado com--allow-file-access-from-files
, --unlimited-storage
e possivelmente reprovado--unlimited-quota-for-files
; Além disso--unsafely-treat-insecure-origin-as-secure=file:///path/to/directory/*
com--user-data-dir=/path/to/directory
conjunto.
Curiosamente, quando o chromium abre, uma notificação é exibida
Você está usando um sinalizador de linha de comando não suportado:--unsafely-treat-insecure-origin-as-secure
. Estabilidade e segurança sofrerão.
Existem outros sinalizadores não especificados que podem ser usados; notificação ignorada, pois ainda era possível definir e obterlocalStorage
àsfile:
protocolo, arquivos especificamente emfile:///path/to/directory/*
, Apesar
navigator.webkitTemporaryStorage.requestQuota(1024*1024, function(grantedBytes) {
console.log(grantedBytes)
}, errorHandler);
logado0
, OndeerrorHandler
é
function errorHandler(e) {
console.log(e)
}
Além disso
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);
}
logado
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
Pergunta: Quais são as modificações necessárias nos sinalizadores de lançamento, soluções alternativas ou outras abordagens que permitiriam o uso dewebkitRequestFileSystem
àsfile:
protocolo?