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 @   ifnk  阅读(323)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
点击右上角即可分享
微信分享提示