I am working with React, and I am trying to upload a file and that file type should be only png. When I upload png file it is working fine. but I need to stop uploading other type files. for example if I need to upload png file means, it's needs to work properly. by mistake if I upload audio file means the file should not be uploaded. Please tell me how to write validations like this.
This is my code This is App.js
import React, { useState } from "react";
import 'antd/dist/antd.css';
import './index.css';
import { Row, Col, Button, Modal, Upload, message } from 'antd';
import { VideoCameraOutlined, AudioOutlined } from '@ant-design/icons';
import "./App.css";
const App = () => {
const props = {
beforeUpload: file => {
const audioValidation = file.type === "image/png"
if (!audioValidation) {
message.error('You can only upload PNG file!');
}
}
}
const [visible, setVisible] = useState(false)
const showPopUp = () => {
setVisible(true)
}
return (
<div>
<Row>
<Col span={24}>
<Button onClick={() => showPopUp()} type="primary">Show PopUp</Button>
<Modal
visible={visible}
>
<Upload {...props}>
<div style={{ display: "flex" }}>
<div>
<VideoCameraOutlined style={{ fontSize: "25px", backgroundColor: "red", padding: "10px", borderRadius: "50%" }} />
<h6>Upload Video</h6>
</div>
<div style={{ marginLeft: "5px" }}>
<AudioOutlined style={{ fontSize: "25px", backgroundColor: "red", padding: "10px", borderRadius: "50%" }} />
<h6>Upload Png</h6>
</div>
</div>
</Upload>
</Modal>
</Col>
</Row>
</div>
)
}
export default App
If you have any questions please let me know, thank you.
.png.