Hey is a decentralized and permissionless social media app built with Lens Protocol 馃尶
1const getFileFromDataURL = (
2 dataUrl: string,
3 fileName: string,
4 callback: (file: File) => void
5) => {
6 const img = new Image();
7 img.crossOrigin = "Anonymous";
8 img.src = dataUrl;
9
10 img.onload = () => {
11 const canvas = document.createElement("canvas");
12 const ctx = canvas.getContext("2d");
13 canvas.width = img.width;
14 canvas.height = img.height;
15 ctx?.drawImage(img, 0, 0, img.width, img.height);
16
17 canvas.toBlob((blob) => {
18 if (blob) {
19 const file = new File([blob], fileName, { type: blob.type });
20 callback(file);
21 }
22 });
23 };
24 img.onerror = () => {
25 // Ignore errors
26 };
27};
28
29export default getFileFromDataURL;