react ant design 单个文件 上传

直接上代码 ,有空后面 写注释

  const [fileList, setFileList] = useState<UploadFile[]>([]);

              <Upload
                name="file"
                multiple={false}
                maxCount={1}
                showUploadList={false}
                fileList={fileList}
                customRequest={options => {
                  setLoading(true)
                  let file = options.file;

    // 这里拿到 file 以后 写你 上传 的 逻辑  
                  console.log("file", file)
                  setLoading(false)
                }}
              >
                <Button size={'mini'} color='primary'>采集视频 </Button>
              </Upload>


补充 , 如果选择多个文件的话,用custormRequest 就不好使了,你选择多个文件 ,他就进多少次 customRequest ,导致你不知道什么时候文件已经放完了,也获取不到数量

这个时候 只能监听 fileList ,有变化 再上传吧 (不好的方法 )

posted @ 2022-03-08 19:35  ifnk  阅读(301)  评论(0编辑  收藏  举报