nodejs怎么模拟input type=file拿到filelist

nodejs怎么得到html中点击<input type="file">选中文件后得到的filelist

阅读 4.9k
2 个回答
  • TALK IS CHECAP, SHOW ME THE CODE

<html>
<body>
  <form>
      <div>
        <label>Select file to upload</label>
        <input type="file">
      </div>
      <button id="taozhi" type="submit">Convert</button>
    </form>
  <script>      
        var p = document.getElementById("taozhi");
        p.onclick = showAlert;
    

      function showAlert(event) {
        // 这就是你需要的吧!!input.files获取选中文件之后的filelist
        const input = document.querySelector('input[type="file"]')
        const file = input.files[0]
        let formData = new FormData();  
        formData.append('image', file);
        fetch('http://localhost:8001/upload',{  
            method:'post',
            body:formData,  
        })  
        .then((response) => response.json() )  
        .then((response)=>{  
          console.log(response)
        })  
        .catch((err)=>console.error(err)); 
      }
    </script>
</body>
</html>

一般模拟的问题都可以用phantomjs解决吧,只是效率问题

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题