1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 微信小程序上传多张图片 上传文件pdf等

微信小程序上传多张图片 上传文件pdf等

时间:2022-08-18 09:24:45

相关推荐

微信小程序上传多张图片 上传文件pdf等

wx.getFileSystemManager().readFileSync同步循环数组是可以拿到值的

wx.getFileSystemManager().readFile异步,但是加了这个就一直是空数组,不得已现在加了一个模特框点击确定的就有值了

var that = this;wx.chooseImage({count: 5, // 默认9sourceType: ['album', 'camera'],sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有success: function (res) {var patharr = []console.log(res.tempFilePaths)// 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片res.tempFilePaths.forEach(function (item, index) {// patharr.push('data:image/png;base64,' + wx.getFileSystemManager().readFileSync(item, 'base64'));//使用异步的wx.getFileSystemManager().readFile({filePath: item, //选择图片返回的相对路径encoding: 'base64', //编码格式success: res => { //成功的回调patharr.push('data:image/png;base64,' + res.data)}})})console.log(patharr)}})

微信小程序上传pdf等文件

var that = thiswx.chooseMessageFile({count: 1,//能选择文件的数量type: 'file', //能选择文件的类型,我这里只允许上传文件.还有视频,图片,或者都可以success(res) {var size = res.tempFiles[0].size;var filename = res.tempFiles[0].name;var newfilename = filename + "";console.log(res);if (size > 4194304 || newfilename.indexOf(".pdf") == -1) { //我还限制了文件的大小和具体文件类型wx.showToast({title: '文件大小不能超过4MB,格式必须为pdf!',icon: "none",duration: 2000,mask: true})} else {that.setData({path: res.tempFiles[0].path, //将文件的路径保存在页面的变量上,方便 wx.uploadFile调用filename: filename //渲染到wxml方便用户知道自己选择了什么文件})console.log(wx.getFileSystemManager().readFileSync(res.tempFiles[0].path, 'base64')) }}})

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