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

How to Convert Object URLs to Blobs for Form Submission?

Susan Sarandon
Release: 2024-10-28 16:07:28
Original
468 people have browsed it

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());
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template