Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

URL: createObjectURL() static method

BaselineWidely available

Note: This feature is available inWeb Workers, except forService Workers.

ThecreateObjectURL() static method of theURL interfacecreates a string containing a URL representing the object given in the parameter.

The URL lifetime is tied to thedocumentin the window on which it was created. The new object URL represents the specifiedFile object orBlob object.

To release an object URL, callrevokeObjectURL().

Note:This feature isnot available inService Workers due to itspotential to create memory leaks.

Syntax

js
URL.createObjectURL(object)

Parameters

object

AFile,Blob, orMediaSource object tocreate an object URL for.

Return value

A string containing an object URL that can be used to reference thecontents of the specified sourceobject.

Examples

Usage notes

Memory management

Each time you callcreateObjectURL(), a new object URL is created, even ifyou've already created one for the same object. Each of these must be released bycallingURL.revokeObjectURL() when you no longer need them.

Browsers will release object URLs automatically when the document is unloaded; however,for optimal performance and memory usage, if there are safe times when you canexplicitly unload them, you should do so.

Using object URLs for media streams

In older versions of the Media Source specification, attaching a stream to a<video> element required creating an object URL for theMediaStream. This is no longer necessary, and browsers are removingsupport for doing this.

Warning:If you still have code that relies oncreateObjectURL() to attach streams to mediaelements, you need to update your code to setsrcObject to theMediaStream directly.

Specifications

Specification
File API
# dfn-createObjectURL

Browser compatibility

See also

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp