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 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!