@kopexa/sight
Version:
Kopexa Sight Design System — React component library for GRC applications
16 lines (13 loc) • 479 B
JavaScript
"use client";
// src/components/file-upload/utils/data-url-to-file.ts
async function dataUrlToFile(dataUrl, fileName, typeHint) {
const res = await fetch(dataUrl);
const blob = await res.blob();
const type = typeHint || blob.type || "image/png";
const ext = type.includes("jpeg") ? "jpg" : type.split("/")[1] || "png";
const safeName = fileName.replace(/\.[^.]+$/, "");
return new File([blob], `${safeName}-cropped.${ext}`, { type });
}
export {
dataUrlToFile
};