小程序中多图片上传( 二 )

图片工具类 custom.js
// 工具类let util = require('../util/util')// 地址接口let api = require('../config/api')/** * 真正上传方法 * @param {图片上传接口} imgPath* @param {图片文件资源地址} filePath*/function uploadList(imgPath, filePath) {return new Promise((resolve, reject) => {wx.uploadFile({url: imgPath,filePath: filePath + "", //获取图片路径header: {'content-type': 'multipart/form-data'},name: 'file',success: function (res) {if (res.statusCode == 200) {resolve(res.data)} else {reject(err, res);}},fail: function (err) {reject(err, res);}});});}/** * 图片上传,多图片上传,同步处理一并返回-虚拟文件地址的list * @param {本地文件list} tempFilePaths*/async function uploadImage(tempFilePaths = []) {let fileList = new Array();for (let i = 0; i < tempFilePaths.length; i++) {let data = https://www.isolves.com/it/cxkf/ydd/xcx/2023-02-03/await uploadList(api.workUpload, tempFilePaths[i]);// 进行设置返回let rt = JSON.parse(data);// 由于之前封装的request方法为application/json类型,所以这里需要特殊处理返回的数据格式let url = (rt.url).replaceAll('"','');fileList.push(url);}return fileList;}module.exports = {orderWork, // listuploadImage, // 多张图片上传}
【小程序中多图片上传】


推荐阅读