createObjectURL method
Creates a URL for the specified object.
![]() |
Syntax
var retval = URL.createObjectURL(object, oOptions);Parameters
- 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.
Exceptions
| Exception | Condition |
|---|---|
|
Thrown when the object passed into createObjectURL is null or not a supported object. |
Remarks
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.
See also
