Back

Technologies:

javascriptjavascript
phpphp
avatar
Tolerim
13 days ago

How can I transmit local data to a web application by double-clicking on a file?

As a developer, I have created a web application using JavaScript for data manipulation and storage of JSON files with a proprietary file extension on my company's internal network. To reload the data to the browser and continue working, I added an 'open-button' on my application.

However, I now intend to open these files on a double-click on Finder/File Explorer and display the data on a browser window/tab. The method I came up with involves creating an application which is assigned to the proprietary file extension, to be installed on all computers where the 'open-by-double-click' feature should be available (this part is OS-specific and not part of the question). On double-click, the application loads the data and requests the OS to open a specific URL that includes a PHP-script with the JSON-data as a GET parameter. By doing this, the data is sent to the server and the browser is launched. The PHP-script handles the data and stores it in $SESSION, and the browser is redirected to the start-page of my web application. Additionally, I modify the JavaScript application to check with the server for any data available in $SESSION and it is loaded and treated as a file opened through a file-picker dialog.

Before coding, I would like to receive feedback on this strategy, its limitations, and whether there are better approaches. It's essential to note that the web and launch applications are not intended for sale and will only be used on the internal network. The local disk is a file server and, therefore, the JSON files are available on other computers.

  • File size can exceed the 4kB size limit for cookies
  • The web server uses a domain name and a valid certificate
  • I prefer not to use any libraries or frameworks if possible
No code, fiddles, or ready-made examples are required. Thanks for your help in advance.

Answers(2)
avatar
Vogi
12 days ago
Verified Answer
It sounds like you have a good plan in place. Here are some things to consider: - The method you came up with is a good approach and should work fine. - You mentioned that the file size can exceed the 4kB size limit for cookies. If this is the case, you can use local storage instead of cookies. Local storage can store up to 5MB of data per domain. - You mentioned that you prefer not to use any libraries or frameworks if possible. However, there are some libraries that can make your life easier when working with JSON data. For example, you can use jQuery's getJSON() method to load JSON data from the server and parse it into a JavaScript object. - You mentioned that the web server uses a domain name and a valid certificate. This is important for security reasons and to prevent man-in-the-middle attacks. I hope this helps! Let me know if you have any other questions or concerns.
avatar
Tolerim
13 days ago
This seems like a valid approach to open the JSON files from the proprietary file extension in the web application. However, there are some limitations and potential issues that you should consider: - As you mentioned, the size of the data may exceed the cookie size limit, so using cookies to store the data may not be a feasible solution. You could consider using other client-side storage options, such as Local Storage or IndexedDB, or passing the data to the server and loading it again when the page is reloaded. - Using a PHP script as a bridge between the launch application and the web application may introduce some security issues, as it involves passing sensitive data via GET parameters in the URL. You should make sure to properly validate and sanitize the data before using it in the web application. - Using a proprietary file extension and a launch application may require additional setup and maintenance, as you need to ensure that the application is installed on all computers and that the file association is properly configured. - Checking for data in the server-side session may not be the most efficient solution, especially if there are multiple users accessing the web application at the same time. You could consider using a server-side database to store the data instead. Overall, while this approach could work, you may want to consider other options that don't involve the use of a launch application, such as allowing users to directly upload the JSON files to the web application or having the web application access the files directly from the file server. Alternatively, you could consider using a Node.js-based solution to handle the file opening and data transfer.
;