Untitled

 avatar
unknown
plain_text
a month ago
809 B
2
Indexable
const docUploadValidation = (fileImage) => {
    const maxFileSize = 4 * 1024 * 1024; // 4MB
    const validImageTypes = ['image/jpeg', 'image/png', 'image/jpg'];
    
    if (fileImage?.length > 0) {
        const file = fileImage[0].file;
        
        // Check if the file is of type 'blob', then set it as image/jpg
        if (file.type === 'blob') {
            file.type = 'image/jpeg'; // Or 'image/jpg'
        }
    
        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