python-eel / Eel

A little Python library for making simple Electron-like HTML/JS GUI apps
MIT License
6.41k stars 585 forks source link

serve all files from root . #686

Open rraammiinn opened 1 year ago

rraammiinn commented 1 year ago

I wanna access to all files in html but it only has access to init directory . I tried to use home as init directory but it didn't work .

thatfloflo commented 1 year ago

@rraammiinn can you please give a minimal working example of what you're trying to do and give a specific example of something that should work but doesn't?

rraammiinn commented 1 year ago

I wana open images in my app by changing src property of an img tag but it can't recognize files outside init directory .

for example I wana use them like this :

ChrisKnott commented 1 year ago

This is by design. If you want to serve files outside this you need to open the files and return the data from a custom handler in Python

rraammiinn commented 1 year ago

can't this feature be added ?

thatfloflo commented 1 year ago

If I understand correctly what you want to do (give the browser unfettered access to the root of your file system, or maybe the root of your python package) this is not something anyone should want to do or that anyone should be easily able to do, because it would present significant security risks.

You could in principle already use a home directory or some such by specifying this in eel.init() [you can in principle even symlink it into a subdirectory of your package's directory] but this is still not a good idea. Give access to only what is strictly needed, for the rest you want to have a way of checking that what someone does via the frontend is really something you'd want to let them do, and for that what @ChrisKnott suggested is the only really safe way to get that done, because it means at least you have to explicitly not care about the security of the data you pipe along.

rraammiinn commented 1 year ago

I tried to use home as init directory as you said but when I ran the program cpu started working madly and my system began freezing and program didn't start ( I think it was searching entire home directory but I think you can fix it) .

doug-benn commented 1 year ago

Hello,

This does seem like a bad idea

Could you return the image from a python function that does have access to a directory outside of init? It can then be called from JavaScript and should give to access to the image?