#Reading files on windows?

50 messages · Page 1 of 1 (latest)

molten perch
#

I have created a new protocol handler and am trying to get files to load on windows. They load fine in linux. I tried replacing the windows \ path with / but that does not work. The error i get is net:ERR_UNEXPECTED

Here is the custom file handler:

        return net.fetch('file://' + request.url.slice('media://'.length))
    })```
marsh lion
#

in which case do you need to load files? I mean, what kind of files?

molten perch
#

local files from out side the app

#

for example C:\test.mp3

#

or /home/me/test.mp3 on linux

marsh lion
#

and you only get this error?

molten perch
#

yup

#

only on windows

#

linux the flatpak works fine compiled

#

windows i get that error

marsh lion
#

do you get it if you don't use a custom protocol?

molten perch
#

dont know never tried it without, let me give it a go

marsh lion
#

if in production you load a file into your window, the custom protocol shouldn't be necessary

molten perch
#

building now for a test on windows using just file://

#

so lets say this works how would i handle the difference between dev and production?

marsh lion
#

in development you get an error about not being able to load local resources?

molten perch
#

yea because chrome has no access to filesystem files for security reasons

marsh lion
#

yes

#

you can just disable webSecurity only in dev

molten perch
#

ok still building took me a minute as im on another computer

marsh lion
#
webPreferences: {
  webSecurity: app.isPackaged,
  allowRunningInsecureContent: false // Optional, save you from a warning in dev
  ...
}
molten perch
#

well that works without the custom handler

#

so now i just need to apply those other fixes. thanks very much for the help

marsh lion
#

you're welcome

molten perch
#

oh and where do those webPrefs go?

#

which file

marsh lion
#

it's in the configuration of your BrowserWindow

molten perch
#

ahh perfect got it

#

should i have any of this other stuff adjusted?

#

i have an idea what node context and backgroud do

marsh lion
#

wow wow, you disabled security stuff 😦

molten perch
#

yea thats why i wanted to chck

#

i dont think i need node intigration as i use no node modules in my app

#

context im not 100% sure on

marsh lion
#

nodeIntegration, contextIsolation, enableRemoteModule, sandbox, all of these are security features

molten perch
#

ok let me kill those lines real fast

marsh lion
#

it will block you from using Node.js into your renderer process directly

molten perch
#

yup and thats ok as im not doing that

marsh lion
#

better keep security on then, the default values are secure, you can just not define them into the preferences

molten perch
#

ok i still have audio playback from my files in dev so i think thats good

#

and its more secure now

marsh lion
molten perch
#

oh cool ill check that out

#

thats what I am working on

marsh lion
#

nice ^^

molten perch
#

thanks you and thanks again for the help

marsh lion
#

no problem

bold belfry