Untitled
unknown
plain_text
10 months ago
1.3 kB
6
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 type is 'Blob' and convert it
if (file instanceof Blob) {
// Get the file extension from the filename and set the appropriate MIME type
const fileExtension = fileImage[0].fileExtension.toLowerCase();
let mimeType = '';
if (fileExtension === 'png') {
mimeType = 'image/png';
} else if (fileExtension === 'jpg' || fileExtension === 'jpeg') {
mimeType = 'image/jpeg';
} else {
mimeType = 'image/jpg'; // Default image type
}
// Update the file type to the determined MIME type
file.type = mimeType;
}
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;
};
Editor is loading...
Leave a Comment