如何验证文件是否已上传?

时间:2021-01-15 17:51:40

标签: reactjs react-native frontend

目前,这里是文件的一些内容:

  <div className="file-body">
                <input
                    id="fileUpload"
                    type="file"
                    accept=".csv"
                    className="file-input"
                    onChange={handleChange}
                />
            </div>
            {loading && (
                <div className="bottomSpinner">
                    <Spinner animation="border" />
                    <br />
                    <div style={{ color: "black" }} />
                </div>
            )}
        </Modal.Body>
        <Modal.Footer>
            <div className="buttonsAndLabels bottomSpace">
                <Button
                    onClick={closeModal}
                    className="submissionButtons cancelButton"
                >
                    Close
                </Button>
                <Button
                    className="submissionButtons"
                    onClick={() => updateDB()}
                >
                    Import
                </Button>
            </div>
        </Modal.Footer>
    </Modal>`

我想要的是当点击导入按钮时我想检查文件是否真的上传了。目前,它不检查。关于如何实现这一点的任何想法?

这里是文件上传的handleChange函数。

/**
 * runs when you select a file to upload
 */
function handleChange(event) {
    const fr = new FileReader();
    setLoading(true);

    fr.onload = event => {
        if (type == "asset") {
            newScopeChangeRequest(event.target.result);
        } else if (type == "adminTable") {
            setPreparedJson(event.target.result);
        }
    };
    fr.readAsText(event.target.files[0]);
    setLoading(false);
}

0 个答案:

没有答案
相关问题