Electron 使用原生net上传文件并同时提交数据到JAVA后台

  • w9_510459
    了解作者
  • 35.3KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-06-09 01:20
    上传日期
Electron 使用原生net上传文件并同时提交数据到JAVA后台,结合node的fs.createReadStream 
000.rar
  • 000
  • main.js
    397B
  • package.json
    256B
  • js
  • upload.js
    4.9KB
  • jquery.min.js
    67.3KB
  • index.html
    1.7KB
  • package-lock.json
    66B
内容介绍
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>net</title> <script src="./js/jquery.min.js"></script> <script type="text/javascript"> const {openFile,postFile}= require("./js/upload.js"); $(function(){ $("#selectFile").click(function(){ openFile("jpg,gif,jpeg,png",false,"selectFileCallback"); }); $("#uploadFile").click(function(){ const uploadFilePath = $("#uploadFilePath").html(); postFile("http://127.0.0.1/demo/login/uploadFileDo.do",uploadFilePath,"uploadCallback","hmForm"); }); }); function uploadCallback(result) { console.log(`uploadCallback ** ${result}` ); let arrFileName = result.data.fileNames.split(","); arrFileName.forEach(element => { const timer = new Date().getTime(); $("#img").append(`<img src="http://127.0.0.1/demo/${element}?${timer}" width="200" height="160" id="faceImg"/>`); }); } function selectFileCallback(result){ let uploadFilePath = ""; let len = result.filePaths.length-1; for(var i=0 ;i<=len;i++){ let filePath = result.filePaths[i]; uploadFilePath += filePath; if(i!=len){ uploadFilePath +="|"; } } $("#uploadFilePath").html(uploadFilePath); } </script> </head> <body> <form id="hmForm"> <input type="text" id="name" name="name" value="李四"/> <input type="text" id="age" name="age" value="28"/> <textarea id="cont" name="cont" value=""></textarea> <br/> <div id="uploadFilePath"></div> <input type="button" value="选择文件" id="selectFile"/> <input type="button" value="上传文件" id="uploadFile"/> <br/> <span id="img"></span> </form> </body> </html>
评论
    相关推荐