Home >Web Front-end >JS Tutorial >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!