Hey is a decentralized and permissionless social media app built with Lens Protocol 馃尶
1import compressImage from "./compressImage";
2import { uploadFileToIPFS } from "./uploadToIPFS";
3
4export const readFile = (file: Blob): Promise<string> => {
5 return new Promise((resolve) => {
6 const reader = new FileReader();
7 reader.addEventListener(
8 "load",
9 () => resolve(reader.result as string),
10 false
11 );
12 reader.readAsDataURL(file);
13 });
14};
15
16const uploadCroppedImage = async (
17 image: HTMLCanvasElement
18): Promise<string> => {
19 const blob = await new Promise((resolve) => image.toBlob(resolve));
20 const file = new File([blob as Blob], "cropped_image.png", {
21 type: (blob as Blob).type
22 });
23 const cleanedFile = await compressImage(file, {
24 maxSizeMB: 6,
25 maxWidthOrHeight: 3000
26 });
27 const attachment = await uploadFileToIPFS(cleanedFile);
28 const decentralizedUrl = attachment.uri;
29 if (!decentralizedUrl) {
30 throw new Error("uploadFileToIPFS failed");
31 }
32
33 return decentralizedUrl;
34};
35
36export default uploadCroppedImage;