Skip to content

fileToBlob()

Creates a new Blob from a File, copying the bytes and keeping file.type as the blob’s MIME type. Handy when an API accepts Blob but you only have File, or you want a plain blob without the File name/lastModified metadata.

Examples:

ts
const blob = fileToBlob(fileFromInput);
await uploadEndpoint(blob);
ts
const blob = fileToBlob(imageFile);
const url = URL.createObjectURL(blob);

Released under the MIT License.