Is it possible to edit a local file without uploading to the browser?
Let's say the client has an HTML file, I want him to be able to use my site's javascript to edit the file without uploading it. Would this be possible?
Thanks.
Yes, it is possible, but only in HTML5 (and only as browsers add support for it...not all do yet), you can find the HTML5 File API here.
Note that the user has to give permission to access the file, from Section 5.9:
Once a user has given permission, user agents should provide the ability to read and parse data directly from a local file programmatically.
Nope, that's not possible and shouldn't be either due to security concerns it may pose otherwise.
Note: This feature is there in HTML5 as pointed out by #Nick Craver, you may want to go for but you should be aware of the fact that HTML5 isn't yet supported by all browsers.
Related
Is there a way to get the physical path with Javascript (or any other library) where the user saved the file he/she downloaded from my Web Application?
No, having such a feature would be a security flaw.
Only Google Chrome support the filesystem-API, but i'm not sure if a website can use this Api.
More informations.
No, unless he/she tells you where they saved it, or unless you control the user of the application's computer. This is a silly question if you think about it logically, do you not think there might be few very major security concerns if you were able to very easily spy on the internals of users computers?
Problem:
User has N browsers installed. As an application I want to store a data shared between all installed browsers.
Requirements:
Support IE9
Possible solution for now: WebSQL using polyfill.
Any another suggestions?
With HTML5 and some of the new JS APIs, there might be a few options.
The newish File API supports everything but IE9. As discussed in this question, you can fill in IE9 support using ActiveX or Java, which ought to do the trick. Because of the sandboxing, this may not immediately allow the browsers to completely interoperate.
If taking user input is an option, I would suggest having the user select and load their preferences file when the app loads. By opening a native file browse dialog, you allow the user to select whatever file they desire, and can use the file API to load the contents and process them.
You can use a similar technique for saving the data, either saving to the file sandbox or opening a specially-formed link (the download attribute) to indicate the browser should save a file. Again, you'll run into IE9 issues that will require ActiveX or Java to fill in.
You can see an example of reading a file from an <input type="file">, which is likely your best option. There are also multiple libraries for file upload (note, I have not personally used any of these).
I'm a first time user, just in the initial stages figuring out if this is going to be useful for me, so forgive any naive questions. I'm using Google Chrome.
Here's my use case -
The user needs to store some information to my application(web based) which may include paths to some files on his system. When the user comes back to access this information via my application, he should be able to click on the links that point to these files on his local disk and open those files.
Now, we know that browsers will not allow this due to security concerns.
I had the following questions
The description for HTML5 FileSystemAPI says that this will allow us to access files from a "sandboxed" section of the users disk.
Does that mean that the files that my user wants to read should only originate from a specific folder on his disk?
Do we get to decide what that location would be? File browser access to Chrome's sandboxed filesystems - i get the idea from this question that chrome decides that.
I would appreciate if someone could throw some light on this. Thanks guys.
AFAIK, the FileSystem API doesn't provide access to files outside the sandbox and the sandbox's location is imposed by the browser. You can use HTML5's File API to let the user upload data, and then store this data using the FileSystem API. However, I don't think this is what you want.
Unrestricted access to a user's filesystem is only possible through a Java applet or another plugin.
how can you retrieve the data from a document with javascript that isn't the page you are on if you have the url of the new document.
what i am trying to do is create a page that has a text field for providing a local file name and a button that retrieves the words from the document provided.
thanks.
HTML5 has a File API that lets you read local files. It's supported in at least Firefox (3.6 and later, I think) and Chrome. I don't know if any other browsers support it yet or not. If you need to support other browsers, you'll have to fall back to something like Flash, but I don't have any experience with that.
Unfortunately, by default Chrome doesn't allow local files to access other local files (each file is considered to be from its own domain). You can explicitly allow it by adding the --allow-file-access-from-files flag when you launch Chrome.
Here's a good introduction to the File API with several examples: http://www.html5rocks.com/en/tutorials/file/dndfiles/.
Browser security does not allow direct access to the local filesystem. If it could, web pages would be able to steal any file of your machine.
HTML5 local storage does allow local access, but on a different principle.
Is it possible to read the contents of an uploaded file (through <form><input type="file">) from inside javascript with no backend? I suppose it's possible with HTML5, but what about HTML4?
You can read (not upload - well, you can upload too, but that's like sending fan-mail to Edgar Allen Poe; nothing stops you but he won't be able to read it) from files if your script runs in a very trusted context.
If anyone on your network is browsing the web in a browser set to give that much trust, disconnect their machine from the network first, make their settings tighter second.
I don't know if I understand correctly. How about using something like uploadify together with jQuery. I guess you'll have to grant the webserver the privilege to write in the specified folders.
The security model will not let you unless you change the security to allow this.
http://www.mozilla.org/projects/security/components/signed-scripts.html
Can you elaborate on what you want to do?
I read the question as "How do I grab the contents from a file chosen using a file upload field and process it on the client without involving a backend/webserver".
I am thinking UniversalBrowserRead access for FF and HTA filesystem for IE for example