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

How to Convert an Object URL to a File or Blob for Upload?

Linda Hamilton
Release: 2024-11-01 00:33:02
Original
171 people have browsed it

How to Convert an Object URL to a File or Blob for Upload?

Retrieving a File/Blob from an Object URL

During drag-and-drop or other image loading operations, object URLs are often used to display images. However, when integrating these images into a form for upload, reversing the object URL into a File or Blob may be necessary.

Modern Solution:

With the introduction of the Fetch API, retrieving a blob from an object URL can be simplified:

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

This method works seamlessly with both object URLs and regular URLs.

The above is the detailed content of How to Convert an Object URL to a File or Blob for Upload?. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!