Home  >  Article  >  Web Front-end  >  How to Convert Object URLs to Blobs for Form Submission?

How to Convert Object URLs to Blobs for Form Submission?

Susan Sarandon
Susan SarandonOriginal
2024-10-28 16:07:28400browse

How to Convert Object URLs to Blobs for Form Submission?

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!

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