Load image from local path (enabling --allow-file-access-from-files)


in my app i want to download some small profile picture of each user to display in the chat, to le the user know who your’re talking to.
i’ve already saved some files (like db, config.json, etc) in User’s document folder, so i’d like to download from my online server those picture ad use them in my chat page.

if i use i got an error “Not allowed to load from local path”.
i’ve set --allow-file-access-from-files when starting electron and set web-security to false, but it’s not working.
any other way to load images?!


A sample code would be helpful


// main.js

// express.js renders chats from sqlite file

      db.all("SELECT * FROM CHAT", function(rows){
          path:app.getPath('documents'), //here i store all data

// chat.ejs renders all the chat messages

   <td class="picture">
    <div class="profilepicture"><img src="file:///<%= path %>/img/<%= data[i].MITTENTE %>.png" /> </div></td>
   <td class="messagebody"><%- data[i].MSG %></td>
   <td class="sender"><%= data[i].MITTENTE %>< /td>
   <td class="datetime"><%= data[i].DATA_ORA %>< /td>

the path in the chat.ejs file is valid, because if i copy it and paste in the browser it shows me the correct file.


in the package.json file i run electron with

"scripts": { 
  "start": "electron . --allow-file-access-from-files"

and i set the web-security to false when i create the BrowserWindow

mainWindow = new BrowserWindow({
    width: 500,
    height: 640,
    titleBarStyle: 'hidden-inset',
    resizable: false,
    x: 0,
    y: 0,


Resolved using express.js
i set a static folder as the user document folder, and used via staic urlo http://localhost:3000/path_to_file/file.jpg