window.requestFileSystem not working
33,478
Solution 1
Only chrome supports requestFileSystem
as the webkitRequestFileSystem
version.
None of the other browsers (FF6, IE9, Op11) support this
Solution 2
Disregarding the security issue that you cannot "browse" local files with a website, your question should be answered:
When requesting a PERSISTENT filesystem you have to request a quota in first. Try that instead:
window.storageInfo.requestQuota(PERSISTENT, 1024*1024,
function(grantedBytes) {
window.requestFileSystem(window.PERSISTENT, grantedBytes, onInitFs, errorHandler);
},
errorHandler
);
Author by
Tony2
Updated on March 22, 2020Comments
-
Tony2 about 4 years
I am trying on Firefox,IE 9,Chrome and Opera the code below ,but the onInitFs(fs) function doesn't get called.if I add '()' to onInitFs in the window.requestFileSystem(window.PERSISTENT, 1024*1024, onInitFs, errorHandler) that function get called but fs is null ? Does anybody know how to solve this problem?I try on windows 7.I'll appreciate very much your help.
<!DOCTYPE HTML> `<html> <head> <script> function errorHandler(e){ alert("errorrrr"); } function onInitFs(fs){ alert("onInitFs"); } function readClick(){ if (window.webkitRequestFileSystem) { window.webkitRequestFileSystem(window.PERSISTENT, 1024*1024,onInitFs,errorHandler); } else { window.requestFileSystem(window.PERSISTENT, 1024*1024, onInitFs, errorHandler); } alert("read finishsssss"); } </script> </head> <body> <input type="button" value="Read dir" onclick="readClick()"> <ul id="filelist"></ul> </body> </html>
-
Tony2 almost 13 years1.thnx but I am trying on chrome as well with webkitRequestFileSystem and the onInitFs(fs) function doesn't work ie doesn't get called
-
Tony2 almost 13 years2.my second question is:do you now any way of getting the list of files of a given folder which would work in almost all browsers?
-
Raynos almost 13 years@Tony2 no. requestFileSystem gives you a sandboxed file system. You cant access local files directly. You can ask users to upload a file through
<input type='file' />
though -
Tony2 almost 13 yearsi appreciate very much your responses,but i don't want to ask user.I need to load from code one by one the images of a given folder without using the trick of naming images like this image1.jpg,image2.jpg,etc in other words images'names are unchangeable .any idea?
-
Tony2 almost 13 yearsthere will be about 100 images
-
Raynos almost 13 years@tony2 You cannot arbitarly access local files using javascript
-
Tony2 almost 13 yearsthank you very much.what if i use php ?can be done any trickby using it for client side please help
-
Raynos almost 13 years@Tony2 the only way to access local files on a users computer would be to use ActiveX (IE only) or Java. Be wary that your forced to use those to bypass security checks. Browser do not allow you to access local files because it's unsecure
-
zumalifeguard over 3 years@Raynos you really shouldn't assume JavaScript cannot run in different context when that's possible such as chrome apps and extensions.