Chapter 6. Files
For obvious reasons, the browser has historically had very limited ability to access the filesystem. HTML forms have been able to upload files, and certain HTTP headers make it possible for a user to download files from the server. But outside of those specific features, the browser has not been able to access files on the local filesystem. In general this is a good thing. I don’t want every web page I visit to be able to look around my hard drive!
Some of the new features of HTML5 give the browser limited access to the filesystem. Newer browsers allow JavaScript to access the files via the exiting form file input. Historically, a browser could upload a file from a form, but now it is possible to use the data from the file directly in JavaScript. In addition, the browser now lets you drag files from your desktop to a web application. Google’s Gmail uses this feature to allow the user to attach files. This had been done with Flash previously, but now can be done with just JavaScript.
This does not create any new security problems, because the application already had access to this data by uploading it to the server, then downloading it again into the browser.
As of this writing, these features are supported in Firefox, Chrome, and Opera. For Safari and Internet Explorer, the Flash plug-in will work to allow file drag-and-drop.
Blobs
JavaScript has always been good at working with strings and numbers, but binary data has never been its strong point. Recently, however, ...
Get Programming HTML5 Applications now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.