Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
343 views
in Technique[技术] by (71.8m points)

webkitdirectory实现web文件夹上传的问题

最近在开发中遇到了个偶现的问题:利用input的webkitdirectory进行文件夹上传,偶现点击上传后 浏览器没有任何反应
操作流程:
1.点击选择文件夹
image.png

2.弹出文件选择框 选择文件夹

3.chrome会自动弹出二次确认
image.png

以下是实现的代码

const uploader = document.createElement("input")
    uploader.multiple = true;
    uploader.name = "file";
    uploader.type = "file";
    uploader.setAttribute("webkitdirectory", "");
    uploader.click();
    uploader.addEventListener("change", (ev: any) => {
      callback()
      xxxxxx
      xxxxxx
      }
    })

按照正常流程 点击上传后 浏览器会执行传入的callback 但是目前会偶现 点击上传后 没走到回调里 概率大概是操作几十次出现一次

有没有大佬路过指点一下 不胜感激


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...