Retrieving Files from Object URLs for Form Submission
When integrating drag-and-drop functionality for image upload, you may encounter a scenario where you need to convert an object URL generated using URL.createObjectURL back to a Blob or File for upload via a form.
To accomplish this task, you can leverage the modern solution provided in the response:
let blob = await fetch(url).then(r => r.blob());
This solution is applicable regardless of whether the url is an object URL or a regular URL. By fetching the resource and using the blob() method on the response, you can obtain a Blob object that can be appended to your FormData object for submission.
The above is the detailed content of How to Convert Object URLs to Blobs for Form Submission?. For more information, please follow other related articles on the PHP Chinese website!