1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > springboot---微信小程序上传文件(word/pdf文件)

springboot---微信小程序上传文件(word/pdf文件)

时间:2018-09-26 21:54:25

相关推荐

springboot---微信小程序上传文件(word/pdf文件)

springboot后台

C:\Users\Lenovo\Desktop\各种框架安装包\demo-uploadfile

(随便一个上传文件的java接口)

wx.js

chose() {var serverUrl = "http://localhost:8080/upload"var that = thisconsole.log('111')wx.chooseMessageFile({count: 1, //能选择文件的数量type: 'file', //能选择文件的类型,我这里只允许上传文件.还有视频,图片,或者都可以success(res) {console.log(res.tempFiles[0])var size = res.tempFiles[0].size;var filename = res.tempFiles[0].name;var newfilename = filename + "";// ||newfilename.indexOf(".pdf")==-1if (size > 4194304) {//我还限制了文件的大小和具体文件类型wx.showToast({title: '文件大小不能超过4MB,格式必须为pdf!',icon: "none",duration: 2000,mask: true})} else {console.log(res.tempFiles[0].path, filename)that.setData({path: res.tempFiles[0].path, //将文件的路径保存在页面的变量上,方便 wx.uploadFile调用filename: filename //渲染到wxml方便用户知道自己选择了什么文件})wx.uploadFile({url: serverUrl, //上传的路径filePath: that.data.path, //刚刚在data保存的文件路径name: 'file', //后台获取的凭据success() {wx.showToast({//做个提示或者别的操作title: '上传成功',icon: "none",duration: 5000,mask: true,success: function (res) {}})}})}}})},

wx.ml

<form bindsubmit="chose"><input name="firstname" value="请输入姓名" /><input name="lastname" value="请输入姓名" /><button formType="submit">提交</button></form>

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。