怎么开发微信小程序转发图片的功能?
在小程序的功能里面,最实用的要数小程序转发功能了,之前小编已经介绍过小程序转发带参数的开发流程,那么今天会为大家补充介绍一下微信小程序转发图片功能怎么开发。
一.开发小程序转发图片的要点
1.选取图片
wx.chooseImage
({ sizeType: [],
// original 原图,
compressed 压缩图,
默认二者都有 sourceType: [],
// album 从相册选图,camera 使用相机,
默认二者都有 success: function (res) { console.log(res); var array = res.tempFilePaths,
//图片的本地文件小程序路径列表 } })
2.转发图片
wx.uploadFile({ url: '',
//开发者服务器的 url filePath: '',
// 要上传文件资源的路径 String类型!!! name: 'uploadFile',
// 文件对应的 key ,(后台接口规定的关于图片的请求参数) header:
{ 'content-type': 'multipart/form-data' },
// 设置请求的 header formData: { },
// HTTP 请求中其他额外的参数 success: function (res) { }, fail: function (res) { } })
二.代码示例
// 点击上传图片upShopLogo: function () { var that = this; wx.showActionSheet({ itemList: ['从相册中选择', '拍照'], itemColor: "#f7982a", success: function (res)
{ if (!res.cancel)
{ if (res.tapIndex == 0) { that.chooseWxImageShop('album') } else if (res.tapIndex == 1) { that.chooseWxImageShop('camera') } } } }) },
chooseWxImageShop: function (type) { var that = this; wx.chooseImage({ sizeType: ['original', 'compressed'], sourceType: [type], success: function (res)
{/*上传单张 that.data.orderDetail.shopImage = res.tempFilePaths[0], that.upload_file(API_URL + 'shop/shopIcon', res.tempFilePaths[0])*/ /*
上传多张(遍历数组,一次传一张) for (var index in res.tempFilePaths)
{ that.upload_file(API_URL + 'shop/shopImage', res.tempFilePaths[index]) }*/ } }) },upload_file: function (url, filePath)
{ var that = this; wx.uploadFile({ url: url, filePath: filePath, name: 'uploadFile', header: { 'content-type': 'multipart/form-data' }, //
设置请求的 header formData: { 'shopId': wx.getStorageSync('shopId') }, // HTTP 请求中其他额外的 form data success: function (res) { wx.showToast({ title: "图片修改成功", icon: 'success', duration: 700 }) }, fail: function (res) { } }) },
以上就是实现微信小程序转发图片功能所需要的小程序代码了,大家复制上述代码就可以开发成功了,步骤很简单,大家如果还有不懂的地方请持续关注微信小程序商店。
微信小程序转发带参数的方法详解
小程序转发怎么做?
微信小程序转发路径怎么设置?
上一篇:微信小程序转发带参数的方法详解
下一篇:微信小程序转发路径怎么设置?
