Comments (10)
I see. I look forward to the possible new api. In the meantime, I use a somewhat alright workwround: limit the directories to load a file, for example in home directory and current work directory, the filename itselft can be obtained from <input type="file"... >
in html (e.g., C:\fakepath\tmp.txt
).
from webui.
If your data is bigger than ~250Kb it won't work actually using WebUI v2.4.0. But will be fixed soon in 2.4.1.
from webui.
For security reasons, all web browsers hide the real absolute file path. But you can easily use the native OS APIs instead. For example, you call your Python function that opens a file dialog and returns the absolute path to the UI.
import win32gui, win32con, os
filter='Python Scripts\0*.py;*.pyw;*.pys\0Text files\0*.txt\0'
customfilter='Other file types\0*.*\0'
fname, customfilter, flags=win32gui.GetOpenFileNameW(
InitialDir=os.environ['temp'],
Flags=win32con.OFN_ALLOWMULTISELECT|win32con.OFN_EXPLORER,
File='somefilename', DefExt='py',
Title='GetOpenFileNameW',
Filter=filter,
CustomFilter=customfilter,
FilterIndex=0)
print 'open file names:', repr(fname)
print 'filter used:', repr(customfilter)
print 'Flags:', flags
for k,v in win32con.__dict__.items():
if k.startswith('OFN_') and flags & v:
print '\t'+k
Or use a third-party module
import easygui
path = easygui.fileopenbox()
from webui.
JavaScript
var result = webui_fn('MyPythonFunction');
alert('Path is: ' + result);
from webui.
Thanks very much for the reply and for the detailed alternatives.
I am aware of the security reasons for all web browsers to hide the real absolute file path.
But since this webui package is intended for processing local content, I wonder whether there is a way to directly access the real absolute file path like electron.js
does.
from webui.
Electron
uses an entirely modified embedded web browser (Chromium), that's why the final result is +100 MB. While WebUI uses only the already installed real web browser. Perhaps, probably we should add an API for opening a file, something like var path = webui_fopen('*.txt');
from webui.
Hey, if you aren't using the browsers file selector I'm not sure this workaround is guaranteed to work on some platforms. For example I am using golang and I'm not sure how to guarantee a file selector will actually open on linux; they could be using firefox on i3 with no installed file browser for all I know... I am new to the project and notice the api just switched, did the file thing ever get explicitly worked out?
from webui.
It sounds stupid when I think about it too long and I'm not a web dev but could you stream the data over the browser like uploading/downloading a file from a website? I have no idea how to code this on webui
from webui.
I already saw the file handling using HTML5/JS in the text editor example.
Another way to do this is by making the backend use OS native APIs to open the file selector, then send the file content to UI using webui_send_raw().
from webui.
I already saw the file handling using HTML5/JS in the text editor example.
Another way to do this is by making the backend use OS native APIs to open the file selector, then send the file content to UI using webui_send_raw().
I think that using the OS native APIs was hassandraga's first suggestion, but I'm planning to support platforms without native file browsers. I'm interested in this text editor example I haven't seen before. I'm using golang currently, I was able to modify the code of the text editor example to transfer the data of the file. This actually works for me at the moment, though it's kind of a stupid workaround for what I'm doing (loading/saving configs/databases). Next I have to figure out how to save the config to a new file (using the web file browser).
from webui.
Related Issues (20)
- console.log(type(index)); Will cause the function to not run HOT 1
- typo in debug log
- calling a backend function onload results in an uncaught referenceerror HOT 7
- Question: How to set position to the center of the screen? HOT 4
- Ubuntu 20.04 is not supported? HOT 17
- Html Form support HOT 2
- Question: how to set full screen display at startup? HOT 8
- [Feature Request] Expose `_webui_find_best_browser` HOT 4
- OS windows title bar HOT 1
- help: is there a way to hide console/cmd ? HOT 7
- How to make only the the server running? (Do not create browser window) HOT 5
- build error in windows using mingw32 HOT 2
- webui support nodejs? HOT 2
- `.mjs` files are responded with `text/plain` rather than `text/javascript` HOT 2
- Binding clarification/improvements HOT 2
- How to create an Android app? HOT 1
- OpenSSL doesn't work in Firefox and Safari HOT 6
- Build failed using WEBUI_USE_TLS option using windows mingw HOT 7
- Deno's example should update
- Edge Browser window won't show up when running as SYSTEM account in Windows HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from webui.