Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.3 kB
4
Indexable
Never
           const { profileImageCompress } = useCompress();
           const [imageFile, setImageFile] = useState<File | undefined>(undefined);
           const [imageFileUrl, setImageFileUrl] = useState<any>();
           const [imageCompressedFile, setImageCompressedFile] = useState<
                File | undefined
                >(undefined);
           const [imageCompressedFileUrl, setImageCompressedFileUrl] =
               useState<any>(undefined);

          <input
            type="file"
            onChange={(e) => {
              if (!e.target.files) return;
              setImageFile(e.target.files[0]);
              setImageFileUrl(URL.createObjectURL(e.target.files[0]));
              profileImageCompress({ file: e.target.files[0] }).then((res) => {
                setImageCompressedFile(res);
                setImageCompressedFileUrl(URL.createObjectURL(res as File));
                console.log("here is from the return", res);
              });
            }}
          />
          <div style={{ display: "flex" }}>
            <img src={imageFileUrl} style={{ height: 300, width: 400 }} />
            <img
              src={imageCompressedFileUrl}
              style={{ height: 300, width: 400 }}
            />
          </div>
Leave a Comment