window.requestFileSystem not working
Asked Answered
S

2

11

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>
Stipend answered 23/7, 2011 at 20:19 Comment(1)
Related: #19802532Elegant
M
14

Only chrome supports requestFileSystem as the webkitRequestFileSystem version.

None of the other browsers (FF6, IE9, Op11) support this

Mussorgsky answered 23/7, 2011 at 20:23 Comment(9)
1.thnx but I am trying on chrome as well with webkitRequestFileSystem and the onInitFs(fs) function doesn't work ie doesn't get calledStipend
2.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?Stipend
@Stipend 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' /> thoughMussorgsky
i 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?Stipend
there will be about 100 imagesStipend
@tony2 You cannot arbitarly access local files using javascriptMussorgsky
thank you very much.what if i use php ?can be done any trickby using it for client side please helpStipend
@Stipend 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 unsecureMussorgsky
@Mussorgsky you really shouldn't assume JavaScript cannot run in different context when that's possible such as chrome apps and extensions.Roveover
P
5

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
);
Popularly answered 12/10, 2012 at 9:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.