We are converting our java-swing based desktop app into web based using javascript + react. Our current swing app uses local file operations heavily and performs lot of read/write actions on client OS. As you know in browser environment it is not very easy/possible performing local file access because of security restrictions. I know there is File API in html5, but all file related operations needs user iteraction (file browse action should be originating from a real human, not by script). Additionally we have als other native features such as port reading etc which are not possible with browser and javascript.
Can we trigger a java program from an html page in same manner for example the application zoom can start its native executable directly from an link. I think during the install of native executable zoom app, it registers himself to windows regedit etc. Can we make same thing for an java app?
Related
I have a web project that I made with HTML-Javascript. I want to use the XML file (in local project folders) in this web project in javascript. Then I want to make a few changes in this XML file and overwrite the same xml file again. How can I do that?
JavaScript runs in the browser and is isolated from the local system. So the usual way is to upload/download the file. However here are several possibilities.
A small server application
Develop and start a small server application for example with node.js. The server part will provide the file system access.
Use a wrapper
A more advanced version of the previous solution, you encapsulate the web application using a wrapper like Electron.
File System Access API
Use the File System Access API available in some of the new Chromium based browsers.
I am looking a functionality like follows for a web application,
User select a local folder with high resolution images.
Resize this images and send to server for processing.
Make folders in the local file system and copy the original high resolution images according to the server response
Can we achieve this without using any locally installed application but with a web application only. Please guide me, which method/technology can I start with.
Browsers will not allow to access local file system due to security reasons. Image any website able to play with local files. Browser provides sandbox where your js app can run.
You best options could be to use webstorage. You have limited capacity there though and it is not accessible directly to user. Different browsers can be varying implementations.
You can do this with node.js and sharp or Imagemagick.
As others have mentioned in browser Javascript cannot access a local file system for security reasons. So you'd have to provide an upload interface to upload the image to a node server first, then you can convert the image into a buffer/data stream resize the buffer and save it again on the server ready to be downloaded.
NodeJs is a Javascript runtime
https://nodejs.org/en/
Express is a application framework you can build a webserver that can execute your javascript
https://expressjs.com/
(You've already said you'd prefer not to but) You could build it as an node desktop application using electron which would have access to the filesystem, but it would be a self contained app not a in browser application.
https://electronjs.org/
Sharp and imagemagick plugins are the most popular nodejs based image processors
https://www.npmjs.com/package/sharp
https://www.npmjs.com/package/imagemagick
Hope this helps you get started
I have been working on a HTML/JavaScript program which requires to be downloaded on to you local computer. I am wanting the program to load .mp3 files form the users music folder and display it. How can I do this locally without PHP.
For security reasons,
All the popular browsers does not let you load files from the local computer by default, unless the user select the file (or drag and drop it) on the browser (html5 example here).
Also, the browsers do not let you see a folder's content so that you know the files inside it.
In order to have full access to the file system with javascript, you need something else.
Web App as a computer app
For now, the best way to build a computer application using Web technologies (HTML, Javascript, CSS), is either NW.js or Electron
NW.js
From their github
NW.js is an app runtime based on Chromium and node.js. You can write native apps in HTML and JavaScript with NW.js. It also lets you call Node.js modules directly from the DOM and enables a new way of writing native applications with all Web technologies.
You can start by building your code as a NW.js app (Getting started doc on their github)
Electron
Form their page
If you can build a website, you can build a desktop app. Electron is a framework for creating native applications with web technologies like JavaScript, HTML, and CSS. It takes care of the hard parts so you can focus on the core of your application.
Node.js
You can use Node.js 's API for file system access (fs doc)
I'd like you to give a tip for my issue. I'm pretty new to javascript so I don't have such overview.
I have a desktop application - it's basically a storega for data (+ some GUI). And there's a set of Javascript files, which are ment to get data from desktop application.
These javascript files runs in every browser - for each browser I've made a extension wrapper. There is also a testing java-webkit browser, which injects these files directly (so no extension's API).
So I need to create communication API between Javascript and desktop application, which is able to run in every environment (browser-specific implementation would be too "expensive" to maintain).
So I was thinking of sockets. But there is only Websocket protocol support in javascript. Client looks simple, but I'm afraid that server-side would require too much work and dependecies.
Could you give me a tip, for other technologies, which compatible with my requirments?
And second question - to the sockets - would it be even possible to access socket on "localhost:port" from these's javascript files, when they are Content scripts running in page's context?
Thank you for advice.
Sockets is the way to do it. #Luckyrat has provided some code on how to do it from a Firefox Addon:
https://stackoverflow.com/a/17459064/3791822
I'm trying to create a client side app in javascript that downloads a sqlite database off a server and allows the user to modify it. This app needs to be all client side though, and can't rely on features only present in firefox for example. Is there any framework you are aware of that provides these features?
(Perhaps emulated of sorts?)
Short answer: you can't.
Long answer: Javascript, by design, cannot access local machine files. If it's okay to keep the db server-side and have the client interact with it, the server can execute queries and updates to the DB based on what the client asks it to do (a la web service). This is true for HTML5 browsers as well.
Some browsers, such as firefox and chrome, come with packages that will allow the browser to talk to sqlite dbs, but they are not written in javascript and can do things that javascript cannot, which is why they are included as browser-specific packages instead of as js scripts.