Please note, this is a STATIC archive of website developer.mozilla.org from November 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

FileSystemEntry.toURL()

This is an experimental technology
Because this technology's specification has not stabilized, check the compatibility table for usage in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the specification changes.

Non-standard
This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.

The FileSystemEntry interface's method toURL() creates and returns a string containing a URL which can be used to identify the file system entry. This is done by exposing a new URL scheme—filesystem:—that can be used as the value of src and href attributes.

Syntax

FileSystemEntry.toURL([mimeType]);

Parameters

mimeType Optional
An optional string specifying the MIME type to use when interpreting the file. This can be used to help deal with files whose types aren't recognized automatically by the user agent. If this parameter is omitted, the user agent uses its standard algorithms to identify the file.

Return value

A DOMString containing a URL that can then be used as a document reference in HTML content, or an empty string if the URL can't be generated (such as if the file system implementation doesn't support toURL()).

Example

If you have a FileSystemFileEntry corresponding to an image file in a file system available to your Web site or app, you can call toURL() to get its URL for use in HTML. If your site is located at https://my-awesome-website.woot, and you have a temporary file system that contains an image file named awesomesauce.jpg, the URL returned by toURL() might be (depending on the browser's implementation) something like "filesystem:https://my-awesome-website.woot/temporary/awesomesauce.jpg".

Code that makes use of this might look like this:

let img = document.createElement("img");

img.src = imageFileEntry.toURL();
document.body.appendChild(img);

Assuming the scenario mentioned before the code, the result would be HTML that looks like this being appended to the end of the document:

<img src="filesystem:https://my-awesome-website.woot/temporary/awesomesauce.jpg">

Specifications

Specification Status Comment
File and Directory Entries API
The definition of 'toURL()' in that specification.
Editor's Draft Initial specification.

This API has no official W3C or WHATWG specification.

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 13 webkit No support No support No support No support
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support No support 0.16webkit No support No support No support No support

See also

Document Tags and Contributors

 Contributors to this page: Sheppy
 Last updated by: Sheppy,