Home > Web Front-end > JS Tutorial > body text

How to Retrieve Files from Object URLs in Modern Browsers?

Barbara Streisand
Release: 2024-10-29 01:36:29
Original
469 people have browsed it

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>
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template