Get the App
SLTechnology News&Howtos  ›  Development  › 

How does WeChat Mini Programs upload files in batch by ES6 Promise.all?

Shulou Source: shulou.com Published: 2022-05-31 21:50:37 09月21日 Update

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

Tags: Documents programs knowledge content articles code value customers clients easy to operate articles easy to understand more read industry information information channels channels learning services Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Shulou Technology OPPO Reno Xiaomi macOS