Untitled
const docUploadValidation = (fileImage) => { const maxFileSize = 4 * 1024 * 1024; // 4MB const validImageTypes = ['image/jpeg', 'image/png', 'image/jpg']; if (fileImage?.length > 0) { let file = fileImage[0].file; // Check if the file is a Blob, and convert it to a File object if (file instanceof Blob && !(file instanceof File)) { file = new File([file], "uploadedBlobFile", { type: file.type }); } if (file.size > maxFileSize) { toast.error("Image size should not exceed 4MB", { autoClose: 3000 }); return false; } if (!validImageTypes.includes(file.type)) { toast.error("File type should be an image (JPEG, PNG, or JPG)", { autoClose: 3000 }); return false; } } return true; };
Leave a Comment