Home  >  Article  >  Web Front-end  >  How to Retrieve Files from Object URLs in Modern Browsers?

How to Retrieve Files from Object URLs in Modern Browsers?

Barbara Streisand
Barbara StreisandOriginal
2024-10-29 01:36:29470browse

How to Retrieve Files from Object URLs in Modern Browsers?

Retrieving Files from Object URLs

When working with drag-and-drop image uploads, you may need to convert files to object URLs for display. However, during form submission, you may want to revert those URLs back to File or Blob objects for attachment to FormData.

Modern Solution

Modern browsers provide the fetch() API, which enables you to fetch a file from both normal and object URLs:

<code class="javascript">let blob = await fetch(url).then(r => r.blob());</code>

Regardless of whether url is an object URL or a regular URL, this method will return a Blob object representing the file.

The above is the detailed content of How to Retrieve Files from Object URLs in Modern Browsers?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn