Home >Web Front-end >JS Tutorial >How to Convert an Object URL to a File or Blob for Upload?

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

Linda Hamilton
Linda HamiltonOriginal
2024-11-01 00:33:02250browse

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>

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!

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