JavaScript Local Folder Access - javascript

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

Related

How to change xml value in local project file with javascript

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.

Use PHP/Javascript to access/display client-side files

I've built an online photo tagging tool that has a low-res mirror of what is on my local laptop. I'd like to find an easy way to display the high-res version of a given image from my local file system.
Currently I have to get the image name from the web tool, paste it into Lightroom's search system and view that way. I'd like to be able to pull up the high res version, either in the browser or another local app, with a single click.
Options I've investigated:
HTML5 File API/FileReader()/fetch()
These cause even more friction than going to Lightroom, as the user has to select files via the OS file selector and the image directory structure is complex.
Configure local web server to host disk-based images
I've looked at hosting the local image directory with a simple web service, but would need to configure HTTPS to prevent cross-zone violations, and that's more client-side config than I'd prefer.
Any solution that would allow me to reference a local file path directly would work, but modern browsers have (rightly) eliminated most direct paths to local file access.
I'm wondering if there is a way to ask an app on the client side to open the file, in the way that browsers will prompt you for permission to open Zoom and join a meeting, or open a link in the client OS app store. If I could find some way to tell Lightroom to open the specific image without having to copy/paste file names, etc.

Is it possible to create txt file using only client side ? ... but to a specific folder

I read a lot about this topic but they are all created long ago and saying it's not possible . So I'm wondering is it possible to manipulate with the root of the downloads folder , without jeopardizing the clients privacy ?... because clearly that's the main issue of this problem .
Or does anyone have any other idea on how to cross this problem of not storing the files into specified browser download folder ?
Here are a couple of ways to create files using a website:
Create the file virtually and then have the user download the file. You could also create a single zip file with an entire folder structure to create a folder structure in the download folder once it's unzipped.
Use the Filesystem API which has terrible support, I think it's pretty much just Chrome that supports it and it's severely limited. Not recommended.
Use something like Emscripten to have a nicer Filesystem API available. That way you can create the folders and files easily before you, you guessed it, create a zip file that the user downloads. Emscripten has a virtual filesystem that you handle using C++ standard file input/output.
Create an extension for the target browser(s) that the user has to install before you can create files in their filesystem. API's for this is somewhat limited but could be a solution for you since it allows direct editing of files as opposed to first zipping and downloading/unzipping a zip file.
Create your website as a Cordova application and use its filesystem API. Note that this doesn't let your website use the users filesystem, but it allows you to easily distribute your website in the form of an installable app that can then use native tech to interact with the filesystem.
There may be more solutions but these are the ways that came to mind. The reason it's a bit problematic to interact with the filesystem is for obvious security issues that arise when a malicious site could then just create a virus in your filesystem and then request that it gets opened by another program on your computer and if the user then presses accept, BAM, virus infested computer.

Loading Files From A Local Folder

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)

Getting all files in directory with ajax

Backstory:
I am creating a development tool for web development. This tool loads a users webpage into an iframe, this allows the program to resize the iframe and simulate mobile screen sizes. I also want to build in a tool that automatically refreshes the iframe when local content is changed. To do this I am going to use Ajax to load files in and every 5 seconds or so compare the file to its previous version from 5 seconds ago. I currently have it working with just one file.
Question:
Is there a way to get all the files in a directory with Ajax. The little javascript same origin rule does not apply because the user is running this tool locally from the same directory as the project, no files from a server are being pulled.
Javascript which runs on the client machine can't access the local disk file system due to security restrictions.
If you want to access the client's disk file system then look into an embedded client application which you serve up from your webpage, like an Applet, Silverlight or something like that. If you like to access the server's disk file system, then look for the solution in the server side corner using a server side programming language like Java, PHP, etc, whatever your webserver is currently using/supporting.

Categories

Resources