From 0db0dc5b278dfaee2835bcbcdcab010870f09917 Mon Sep 17 00:00:00 2001 From: Wind-Explorer <66894537+Wind-Explorer@users.noreply.github.com> Date: Tue, 13 Aug 2024 02:07:32 +0800 Subject: [PATCH] image upload only --- client/src/components/InsertBillImage.tsx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/client/src/components/InsertBillImage.tsx b/client/src/components/InsertBillImage.tsx index dcfeeef..8561221 100644 --- a/client/src/components/InsertBillImage.tsx +++ b/client/src/components/InsertBillImage.tsx @@ -3,6 +3,7 @@ import config from "../config"; import instance from "../security/http"; import { AxiosResponse } from "axios"; import { Card } from "@nextui-org/react"; +import { popToast } from "../utilities"; interface InsertImageProps { label: string; @@ -65,6 +66,13 @@ const InsertBillImage: React.FC = ({ ) => { const selectedFiles = event.target.files as FileList; const file = selectedFiles?.[0] || null; + + if (file && !file.type.startsWith("image/")) { + console.error("Selected file is not an image."); + popToast("Please upload only image.", 2); + return; + } + setSelectedFile(file); setPreviewImage(file ? URL.createObjectURL(file) : ""); onImageSelected(file);