Skip to Content
Using the HTML5 Filesystem API
book

Using the HTML5 Filesystem API

by Eric Bidelman
July 2011
Intermediate to advanced
72 pages
1h 13m
English
O'Reilly Media, Inc.
Content preview from Using the HTML5 Filesystem API

Chapter 7. Using Files

Chapter 4 focused on common operations for working with files such as reading, writing, and removing files. It did not discuss in detail the ways in which an application can utilize a file residing in its filesystem. However, in most scenarios, you do not need to read the contents of a file in order to use it.

Filesystem URLs

Perhaps the easiest way to use a file is to reference it by URL. The HTML5 Filesystem API exposes a new type of URL scheme, filesystem:. The structure of a filesystem URL is as follows:

filesystem:<ORIGIN>/<STORAGE_TYPE>/<FILENAME>

The format is the scheme, filesystem:, followed by the application’s origin, the storage type the filesystem was requested with, and finally, the full path of the file or folder as it resides on the filesystem. For example, if your application lived at http://www.example.com/myapp and used PERSISTENT storage, the filesystem URL to the root folder would be: filesystem:http://www.example/temporary/.

So why are filesystem URLs handy? They’re useful because they can be used anywhere a normal URL can be used. For example, you could cache a .js file and later use that file’s URL to fill a script.src on demand. You could do the same with a .html file, but instead populate an iframe.src. Lastly, you could display an image by setting its src to a filesystem URL.

Currently in Chrome, filesystem URLs are guessable—one can be constructed manually by knowing the proper format. This might not always be the case and other browser ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

HTML5 Geolocation

HTML5 Geolocation

Anthony T. Holdener
HTML5 Hacks

HTML5 Hacks

Jesse Cravens, Jeff Burtoft
HTML5 Unleashed

HTML5 Unleashed

Simon Sarris

Publisher Resources

ISBN: 9781449311384Errata Page