How does WeChat Mini Programs upload files in batch by ES6 Promise.all?
This article mainly introduces WeChat Mini Programs how to achieve ES6 Promise.all batch upload file related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that after reading this WeChat Mini Programs how to achieve ES6 Promise.all batch upload file article will have a harvest, let's take a look.
WeChat Mini Programs ES6Promise.all batch upload file implementation code
Client
Page ({onLoad: function () {wx.chooseImage ({count: 9, success: function ({tempFilePaths}) {var promise = Promise.all (tempFilePaths.map ((tempFilePath, index) = > {return new Promise (function (resolve, reject) {wx.uploadFile ({url: 'https://www.mengmeitong.com/upload', filePath: tempFilePath) Name: 'photo', formData: {filename:' foo-' + index, index: index}, success: function (res) {resolve (res.data) }, fail: function (err) {reject (new Error ('failed to upload file'));})); promise.then (function (results) {console.log (results);}) .catch (function (err) {console.log (err)) });})
Server side