Cannot open local file - Chrome: Not allowed to load local resource

后端 未结 14 1451
不知归路
不知归路 2020-11-22 12:01

Test browser: Version of Chrome: 52.0.2743.116

It is a simple javascript that is to open an image file from local like \'C:\\002.jpg\'

function run(         


        
相关标签:
14条回答
  • 2020-11-22 12:59

    Chrome and other Browser restrict the access of a server to local files due to security reasons. However you can open the browser in allowed access mode. Just open the terminal and go to the folder where chrome.exe is stored and write the following command.

    chrome.exe --allow-file-access-from-files
    

    Read this for more details

    This way, However, didn't work for me so I made a different route for every file in a particular directory. Therefore, going to that path meant opening that file.

    function getroutes(list){ 
        list.forEach(function(element) { 
            app.get("/"+ element, function(req, res) { 
                res.sendFile(__dirname + "/public/extracted/" + element); 
           }); 
       }); 
    }
    

    I called this function passing the list of filename in the directory __dirname/public/extracted and it created a different route for each filename which I was able to render on server side.

    0 讨论(0)
  • 2020-11-22 13:02

    Know this is kind of old, but see many questions like this...

    We use Chrome a lot in the classroom and it is a must to working with local files.

    What we have been using is "Web Server for Chrome". You start it up, choose the folder wishing to work with and go to URL (like 127.0.0.1:port you chose)

    It is a simple server and cannot use PHP but for simple work, might be your solution:

    https://chrome.google.com/webstore/detail/web-server-for-chrome/ofhbbkphhbklhfoeikjpcbhemlocgigb

    0 讨论(0)
提交回复
热议问题