小编Aru*_*rya的帖子

使用 react-dropzone 上传文件进度

使用 react-dropzone 上传文件,我想以文件传输或 mbs 数据传输的百分比来实现文件进度。

这是链接:https : //react-dropzone.netlify.com/

onDrop(acceptedFiles, uploadApi) {
  const filesToBeSent = this.state.filesToBeSent;
  if (acceptedFiles.length) {
    if (acceptedFiles[0].type === FileTypeList.TYPE) {
      filesToBeSent.push(acceptedFiles);
      const formData = new FormData();
      formData.append("file", acceptedFiles[0]);
      uploadApi(formData).then((response) => {
        this.setState({
          filesPreview: [],
          filesToBeSent: [{}],
          showNotification: true,
          uploadResponse: response,
        });
        this.props.fetchHistory();
      });
    } else {
      this.setState({
        fileType: true,
      });
    }
  } else {
    this.setState({
      fileSize: true,
    });
  }
}
Run Code Online (Sandbox Code Playgroud)
<Dropzone maxSize={this.props.maxSize} onDrop={(files) => this.onDrop(files, this.props.uploadApi)}>
  {({ getRootProps, getInputProps }) => {
    return (
      <div {...getRootProps()} …
Run Code Online (Sandbox Code Playgroud)

reactjs react-dropzone

2
推荐指数
2
解决办法
9205
查看次数

标签 统计

react-dropzone ×1

reactjs ×1