Reputation: 22304
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
Upvotes: 1
Views: 1532
Reputation: 265
The answer to this question has changed since more featues have been added to web standards.
In modern times it is possible to do what you require with the WebAPI File System API. In particular you can use window.showOpenFilePicker()
to open the browsers files system UI to get access to a file (which is represented by a (promise to) a FileSystemFileHandle
object. In the same vein you can use say window.showSaveFilePicker()
to save data to a local file.
Do bare in mind that some of the API features are gated by user activation, which means for example that you can only open a request to get access to a file by say running a Js function as a result of a button click.
Upvotes: 1
Reputation: 986
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.
Upvotes: 1