This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

createObjectURL

Summary

Creates a URL for the specified object.

Method of apis/file/URLapis/file/URL

Syntax

var objectURL = URL.createObjectURL(object, options);

Parameters

object

Data-type
function

The object that needs a URL. Usually a File.

options

Data-type
DOM Node

(Optional)

A dictionary object. See ObjectURLOptions for more information. Used with oneTimeOnly attribute to create a single use URL that does not need to be revoked.

Return Value

Returns an object of type StringString

A URL for the specified object.

Examples

Displaying an image based on the selected file in a <input type=file>

var url = URL.createObjectURL(inputElement.files[0]);
imgElement.src = url;

View live example

Notes

The URL that is created can be used for resources for use with elements such as Image, video, and audio. The object passed in through object is stored in an internal hash table. oOptions is set when you want to only use the URL once. The ObjectURLOptions object has one property, oneTimeOnly, that is set to false by default. To set the URL for the object (blob, stream, and so forth) to single use, use the ObjectURLOptions object and set oneTimeOnly to true. To revoke a URL created with createObjectURL, use revokeObjectURL.

Related specifications

W3C File API Specification
W3C Working Draft

Attributions