Hosting app on a Windows Network Drive


#1

We use a Windows network drive at work so everyone has access to the files on that drive. I’d like my (nodejs) electron app also to have access to those files. What’s the best approaching for this? Presumably I would have to host the app on the network drive. Then do I interact with the file system through something like node’s fs module? Will I have permissions/access issues because the files will be outside the app project folder?


#2

If a person is running the Electron app, then the app will have access to everything that person has access to (this is why Electron uses Node in the first place). You don’t have to host the app on a network drive, no. Yes, you would use Node’s fs module to interact with the file system.


#3

Ok, thanks for clearing that up. Presumably that would be a lot slower than the performance I get when I run the app with localhost and access images/videos directly from my project folder?
I will need to access a lot of images and videos so i would like to optimise it as much as possible…


#4

I wouldn’t presume that without knowing a lot more about the speed of your network, the server the files are served from and the speed of your hard drive. If you really want to understand the relative performance of something, measure it.


#5

Fair point… Is there any chance you could help me with an example of reading an image and/or video file using fs? I’ve managed to read basic text files but I can’t figure out how to read images/videos.
Just for context, i’m using Angular2 with Meteor so I believe I would need to read the file on Meteor’s server side and return the data to the client to be served in my angular component


#6

You read images or videos the same way, using the Node file system module. You need to ensure that you don’t specify an encoding because you want the raw binary data. Additionally, if the image or video is really big, you might want to read it only a piece at a time.

I don’t know anything about Angular or Meteor, so I won’t be of any help there :grinning:


#7

I managed to get this working but as I expected loading the images through fs is much slower than just sourcing them directly (from within the project folder). Is there no way I can get electron to source images from outside the project folder (but still from a shared local network drive)?


#8

There may well be. Unfortunately, that’s outside of my area of expertise. You may want to check on the Atom and Electron Slack too to see if anyone has any suggestions.


#9

You can use file:// URLs; e.g. <img src=file:///home/me/pictures/image.png>


#10

Hi @john, naturally that was what I tried first but I get the following error:

Not allowed to load local resource:

Do you know any way round this? Cheers


#11

It works for me in a BrowserWindow. I guess you’re using a webview which I’m not familiar with.


#12

ahh I see. I’m running electron with meteor which has pretty much been plug and play so i’m not sure how to use a browser window. I’ll do some investigating, thanks for your help!


#13

I have other question, but strict related to this topic. What should I do to run electron app from network drive? I prepared application and distributed it to win32. When I copy whole folder on the local network drive and try to run it I get error that modules cannot load. Line with error is eg. require(“lodash”).