URL.createObjectURL()

You’re reading the English version of this content since no translation exists yet for this locale. Help us translate this article!

URL.createObjectURL() 정적 메소드는 DOMString 을 생성합니다. 이것은 인자로 넘겨지는 객체를 표현하기 위한 URL을 포함합니다. URL의 생명주기는 이것이 생성된 윈도우의 document 에 의존합니다. 생성된 URL은 특정 File 개체나 Blob 개체가 됩니다.

URL 개체를 해제하기 위해서는 revokeObjectURL() 를 호출하십시오.

주의: 이 기능은 Web Worker에서 사용할 수 있습니다.

Note: This feature is not available in Service Workers due to its potential to create memory leaks.

Syntax

objectURL = URL.createObjectURL(object);

Parameters

object
A File, Blob or MediaSource object to create an object URL for.

Return value

A DOMString containing an object URL that can be used to reference the contents of the specified source object.

Examples

Using object URLs to display images 를 보세요.

Usage notes

Memory management

Each time you call createObjectURL(), a new object URL is created, even if you've already created one for the same object. Each of these must be released by calling URL.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 can explicitly 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 the MediaStream. This is no longer necessary, and browsers are removing support for doing this.

Important: If you still have code that relies on createObjectURL() to attach streams to media elements, you need to update your code to simply set srcObject to the MediaStream directly.

Specifications

Specification Status Comment
File API
The definition of 'createObjectURL()' in that specification.
Working Draft Initial definition.
Media Source Extensions
The definition of 'URL' in that specification.
Recommendation

MediaSource extension.

Older versions of this specification used createObjectURL() for MediaStream objects; this is no longer supported.

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
createObjectURL
Experimental
Chrome Full support 8Edge Full support 12Firefox Full support 19
Notes
Full support 19
Notes
Notes createObjectURL() is no longer available within the context of a ServiceWorker.
IE Full support 10Opera Full support 15Safari Full support 6WebView Android Full support YesChrome Android Full support 18Firefox Android Full support 19
Notes
Full support 19
Notes
Notes createObjectURL() is no longer available within the context of a ServiceWorker.
Opera Android Full support 14Safari iOS Full support 6Samsung Internet Android Full support Yes
No longer accepts MediaStream objectChrome ?
Notes
?
Notes
Notes See here for progress on deprecation.
Edge ? Firefox Full support 62IE ? Opera ?
Notes
?
Notes
Notes See here for progress on deprecation.
Safari ?
Notes
?
Notes
Notes See here for progress on deprecation.
WebView Android ?
Notes
?
Notes
Notes See here for progress on deprecation.
Chrome Android ?
Notes
?
Notes
Notes See here for progress on deprecation.
Firefox Android Full support 62Opera Android ?
Notes
?
Notes
Notes See here for progress on deprecation.
Safari iOS ?
Notes
?
Notes
Notes See here for progress on deprecation.
Samsung Internet Android ?

Legend

Full support  
Full support
Compatibility unknown  
Compatibility unknown
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.
See implementation notes.
See implementation notes.

See also