javascript - How to use webkitRequestFileSystem at file: protocol -
according exploring filesystem apis at
browser support & storage limitations
you may need
--allow-file-access-from-files
flag if you're debugging appfile://
. not using these flags result insecurity_err
orquota_exceeded_err
fileerror.
launched chromium --allow-file-access-from-files
, --unlimited-storage
, possibly deprecated --unlimited-quota-for-files
; --unsafely-treat-insecure-origin-as-secure=file:///path/to/directory/*
--user-data-dir=/path/to/directory
set.
interestingly, when chromium opens notification displayed
you using unsupported command-line flag:
--unsafely-treat-insecure-origin-as-secure
. stability , security suffer.
there other flags not specified can used; ignored notification still able set , localstorage
@ file:
protocol, spcecifically files @ file:///path/to/directory/*
, though
navigator.webkittemporarystorage.requestquota(1024*1024, function(grantedbytes) { console.log(grantedbytes) }, errorhandler);
logged 0
, errorhandler
is
function errorhandler(e) { console.log(e) }
also
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); }
logged
fileerror {code: 7, name: "invalidstateerror", message: "an operation depends on state cached in in…he state had changed since read disk."} code:7 message:"an operation depends on state cached in interface object made state had changed since read disk." name:"invalidstateerror" __proto__:domerror
question: modifications necessary @ launch flags, workarounds or other approaches allow use of webkitrequestfilesystem
@ file:
protocol?
the initial try received errors @ terminal
relating lack of space on device. received 2 separate errors code 7
invalidstateerror
, code 3
aborterror
. note, chromium launched in sandbox @ each configuration.
was able achieve expected result of writing filesystem
@ file:
protocol adjusting launch flags --allow-file-access-from-files
, specifying different chromium configuration folder @ --user-data-dir=/newer/version/of/profile/folder
; --unlimited-quota-for-files
, --unsafely-treat-insecure-origin-as-secure=file:///path/to/directory/*
not necessary achieve requirement.
not entirely why original profile folder using logged errors when attempting access filesystem
@ file:
protocol. folder have been previous version of chromium. launch new or newest version chromium command-line chromium
folder in configuration directory may have been older version preferences set. when reviewed terminal
@ 1 point no space left on disk
message logged in relation filesystem
when launched using former profile configuration folder. tried newer version of chromium profile folder solved issue.
much credit solution due @patrickevans verifying process indeed possible; more user error limiting realization of expected result.
var requestedbytes = 16, _grantedbytes; function errorhandler(e) { console.log(e) } function writefile(fs) { console.log(fs) fs.root.getfile("file.txt", { create: true }, function(fileentry) { fileentry.createwriter(function(filewriter) { filewriter.onwriteend = function(e) { // call `readfile` console.log(_grantedbytes); window.webkitrequestfilesystem(window.temporary , _grantedbytes , readfile , errorhandler); }; filewriter.onerror = errorhandler; var blob = new blob(["abc"], { type: "text/plain" }); filewriter.write(blob); }, errorhandler); }, errorhandler); } navigator.webkittemporarystorage.requestquota(requestedbytes , function(grantedbytes) { console.log(grantedbytes); _grantedbytes = grantedbytes; window.webkitrequestfilesystem(window.temporary , grantedbytes , writefile , errorhandler); }, 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, fileentry.tourl()); }; reader.readastext(file); }, errorhandler); }, errorhandler); }
Comments
Post a Comment