Windows apps
Collapse the table of content
Expand the table of content
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

createObjectURL method

Creates a URL for the specified object.

Internet Explorer 10



var retval = URL.createObjectURL(object, oOptions);


object [in]

Type: object

The object that needs a URL. This object may be one of the following types:

  • Blob
  • MSStream
  • IStorageItem (storage file)
  • MediaCapture (webcam preview object)
  • IRandomAccessStreamWithContentType (thumbnail type)

    When createObjectURL is called on an IRandomAccessStreamWithContentType, the reference to this stream now belongs to the blob: URL that is created. The URL also closes the stream when it's revoked. Don't close this stream as that invalidates the blob: url.

oOptions [in, optional]

Type: ObjectURLOptions

Used with the oneTimeOnly attribute that when set to true creates a one-time use URL that doesn't need to be revoked once it's used.

sURL [out]

Type: String

A Blob that represents the specified object.

Return value

Type: String

A Blob that represents the specified object.



Thrown when the object passed into createObjectURL is null or not a supported object.



The Blob that is created can be used for resources in elements such as Image, video, audio, XMLHttpRequest, css backgroundImage, and css fonts.

The blob: URL returned by createObjectURL is valid for the lifetime of the creating document, or until revokeObjectURL is called explicitly. In most cases developers should revoke the URL once finished using it to avoid inadvertently holding on to memory.

The ObjectURLOptions object has one property, oneTimeOnly, that is set to false by default.

If a URL is only expected to be used once (for example, only shown in one Image tag), then the lOptions argument can be set to oneTimeOnly = true to revoke the URL automatically once used. For URLs created for MSStream objects, oneTimeOnly is automatically set to true as these objects are inherently single-use objects.

To revoke a URL created with createObjectURL, use revokeObjectURL.

Note  Blob urls are subject to an origin policy. This means that they can only be used in documents that have the same site-of-origin as the document running the script that created the url. If you need to use the blob object from an <iframe> that is running in a different domain, you must use the postMessage API to send the blob data to the frame and then create the blob: url there.

See also




© 2017 Microsoft