Saving Form data to file - javascript

I want make a simple HTML application with a form. I want to be able to save the data to a file and also read it.
It will be an application that is just for offline use (me and 1 other person will use it). But since I won't be the only one using it I want to be able to share the data with the other person.
So using local storage is not an option. That data cannot be saved, and I don't accidently want to lose that data.
I also tried using blobs, but that only offers download option and it downloads to your download folder. I would like to save the file to the location of the HTML file.
Is that possible with plain HTML and JS? Or do I need to look into some other technologies?
Thanks in advance!

Browser javascript don't have access to the file system and so it won't allow to create file in the local directory. if you want to achieve such functionality you should try sending the file to backend like node js and write the file to the directory.

Related

Js - Create a file and save it to a specific folder in the project

I created an excel file via javascript, but when I need to save it the only option is to have the user open the download window and download the file. I, on the other hand, would like the file to simply be stored in a folder in my project, without the user having the option to download the file.
How can I do this? Thank you
You don't provide enough information but seems that you are doing it on the client side (i.e. a browser), which, in principle, does not have access to the file system on your computer/server.
You should try some Back-end approach, like, in your case with JavaScript: Node.js, or maybe anothers like Python or PHP.

Is it possible to get access permission for a folder in local file system from browser

I want to make a local file editor. To open some files edit them and save them back. It's ok if it only works in Chrome. Using
<input type="file" id="filepicker" name="fileList" webkitdirectory multiple />
I can read all the files and draw the file tree but I want to also be able to edit and save to these files. Even create new files and folders.
Is there any way to do it. I'm also ok with hacks that use Java or Flash or simply any other hack if HTML5 does not offer any solution.
Thanks
I do not believe what you are suggesting is possible; however, there is a different approach that should solve your problem.
If you take Microsoft's Online Word for example... They have it setup so you save document to the cloud and then can edit them with an online copy of Microsoft Word.
In otherwords, the user would upload a file. Your server would then take the file, display it and allow the user to edit the file. The user would then save the changes to the file. You can then provide an option to re-download the file.
To more closely emulate editing a file on the local file system, you can also setup a "temporarily" save on the server.
Essentially, the user uploads a file. The server would allow the user to view and edit the file. When the user wishes to save it, instead of saving the file on the server, give it back as a download to the user.
After the user leaves your site you can delete the copy of the file that is saved on your server.

Save data in a local file with HTML, Javascript?

I'd like to develop a simple offline html page to track my working hours. I'd need an offline file where I can put all my information and then retrieve them through Javascript. What do you suggest me? XML, Json, a DB? I need a "physical" local file because I would like to take my folder with all my html, css, and js files, put it in a pen drive and then open it in another computer. So something portable.
You can't do that offline; HTML/JavaScript doesn't have the ability to write to the filesystem. You can create cookies or use .localStorage in JavaScript, but that would only be local to your browser and won't be visible on another computer.
The closest thing you could possibly get is to write a page that stores data in localStorage and then run it from a portable version of your favorite browser that you also keep on your portable drive.
If you are not set on only using HTML, you might look into doing a C# windows form application.
You can find more on how to leverage that StreamWriter Class here:
https://msdn.microsoft.com/en-us/library/system.io.streamwriter(v=vs.110).aspx
However as for file type, a local JSON or .csv file should do the trick.

How to access filename from a folder using JavaScript

I am trying to build a simple website with just an index file and a folder full of icons for our internal purpose. I am making this so that anyone in our team can just access the link and download the icons whenever needed without our help. I am trying to read the icons file name from the folder automatically, so every time we update the folder with new ones we don't have to edit the HTML. I know only JavaScript. Please help me.
An alternative could be to produce a filelist of the files via a script or batch file (depending on OS, something like - in psudeo - ls path/to/images > filelist.txt) which redirect the output to a file that ends up in the same root as the index and images.
This file could then be read via fetch() or XMLHttpRequest() and parsed on client side to provide the basis for the links to the updates files.
This would require an extra step in the pipe-line of course, but could easily be automated using a listener for the image directory that triggers the script, part of your project setup and so forth.
This is not possible. In your case Javascript is running in the browser (client-side). It has no access to the servers filesystem. You need a server-side dynamic web-service (php, node.js, ...)

How to browse local files from Django and store the file information

I'm new to Django and want to give a user the ability to browse through their local files and "upload" them. However I do not actually want to store their files on my database, I only want to get the filename, path, memory etc of the file the user has selected. I have read through Need a minimal Django file upload example, and many more sites, but everything talks about uploading a file. Any advice would be appreciated!
Thanks
The only interface to local files available in a web browser is the File-picker, as if to select a file for upload. But, you don't have to upload the files! You can work with them in Javascript instead. See for example's Mozilla's documentation on "Using files from web applications".
Note that the Javascript File objects you get back have name, size, and [MIME] type properties.
Your client-side Javascript could poke these into a form, that the user then submits to your server-side Django application. Or, the client-side Javascript could put them into an AJAX action that submits them to the server-side Django application.

Categories