URL.createObjectURL() - Web APIs 编辑

The URL.createObjectURL() static method creates a DOMString containing a URL representing the object given in the parameter. The URL lifetime is tied to the document in the window on which it was created. The new object URL represents the specified File object or Blob object.

To release an object URL, call revokeObjectURL().

Note:

This feature is available in Web Workers.

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

Syntax

const 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

    See 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 set srcObject to the MediaStream directly.

    Specifications

    SpecificationStatusComment
    File API
    The definition of 'createObjectURL()' in that specification.
    Working DraftInitial 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

    BCD tables only load in the browser

    See also

    如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

    扫码二维码加入Web技术交流群

    发布评论

    需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
    列表为空,暂无数据

    词条统计

    浏览:70 次

    字数:5820

    最后编辑:7年前

    编辑次数:0 次

      我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
      原文