小程序
小游戏
企业微信
微信支付
扫描小程序码分享
2 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
chooseimage: function () { var that = this; wx.chooseImage({ count: 1, // 默认9 sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有 sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有 success: function (res) { console.log(res) if (res.tempFilePaths.length > 0) { //图如果满了9张,不显示加图 if (res.tempFilePaths.length == 9) { that.setData({ hideAdd: 1 }) } else { that.setData({ hideAdd: 0 }) } //把每次选择的图push进数组 let img_url = that.data.img_url; for (let i = 0; i < res.tempFilePaths.length; i++) { img_url.push(res.tempFilePaths[i]) } that.setData({ img_url: img_url }) } } }) }, //发布按钮事件 send: function () { var that = this; var user_id = wx.getStorageSync('openid') wx.showLoading({ title: '上传中', }) wx.showToast({ title: '发布成功', icon: 'success', duration: 3000 }) that.img_upload() }, //图片上传 img_upload: function () { let that = this; let img_url = that.data.img_url; let img_url_ok = []; let content = that.data.content; let id = that.data.openid; //由于图片只能一张一张地上传,所以用循环 for (let i = 0; i < img_url.length; i++) { //console.log(img_url), console.log(app.globalData.openid) console.log(that.data.img_url) console.log(content) wx.request({ url: '', header: { "content-type": "application/x-www-form-urlencoded" }, method: 'POST', data: { openid: app.globalData.openid, fileimgs: that.data.img_url, title: content, }, success: function (res) { //隐藏提示文字 wx.hideLoading() console.info(res); // wx.navigateTo({ // url: '/pages/dongtai/dongtai', // }) }, fail: function (res) { console.log('上传失败') } }) } }
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
你是不是把文件id上传上去了
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
chooseimage: function () { var that = this; wx.chooseImage({ count: 1, // 默认9 sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有 sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有 success: function (res) { console.log(res) if (res.tempFilePaths.length > 0) { //图如果满了9张,不显示加图 if (res.tempFilePaths.length == 9) { that.setData({ hideAdd: 1 }) } else { that.setData({ hideAdd: 0 }) } //把每次选择的图push进数组 let img_url = that.data.img_url; for (let i = 0; i < res.tempFilePaths.length; i++) { img_url.push(res.tempFilePaths[i]) } that.setData({ img_url: img_url }) } } }) }, //发布按钮事件 send: function () { var that = this; var user_id = wx.getStorageSync('openid') wx.showLoading({ title: '上传中', }) wx.showToast({ title: '发布成功', icon: 'success', duration: 3000 }) that.img_upload() }, //图片上传 img_upload: function () { let that = this; let img_url = that.data.img_url; let img_url_ok = []; let content = that.data.content; let id = that.data.openid; //由于图片只能一张一张地上传,所以用循环 for (let i = 0; i < img_url.length; i++) { //console.log(img_url), console.log(app.globalData.openid) console.log(that.data.img_url) console.log(content) wx.request({ url: '', header: { "content-type": "application/x-www-form-urlencoded" }, method: 'POST', data: { openid: app.globalData.openid, fileimgs: that.data.img_url, title: content, }, success: function (res) { //隐藏提示文字 wx.hideLoading() console.info(res); // wx.navigateTo({ // url: '/pages/dongtai/dongtai', // }) }, fail: function (res) { console.log('上传失败') } }) } }
要么用wx.uploadFile,要么把图片读成二进制流。。
你是不是把文件id上传上去了