微信小程序 ES6Promise.all批量上传文件实现代码
程序员文章站
2023-02-16 08:06:42
微信小程序 es6promise.all批量上传文件实现代码
客户端
page({
onload: function() {
wx.choose...
微信小程序 es6promise.all批量上传文件实现代码
客户端
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); }); } }); } });
服务端
<?php use illuminatehttprequest; route::post('/upload', function (request $request) { if ($request->photo->isvalid()) { $request->photo->storeas('images/foo/bar/baz', $request->filename . '.' . $request->photo->extension()); return ['success' => true, 'index' => $request->index]; } });
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
上一篇: 电脑系统没有新建文本文档怎么解决?