微信小程序 ES6Promise.all批量上傳文件實現(xiàn)代碼
更新時間:2017年04月14日 15:13:45 作者:馬小云
這篇文章主要介紹了微信小程序 ES6Promise.all批量上傳文件實現(xiàn)代碼的相關(guān)資料,需要的朋友可以參考下
微信小程序 ES6Promise.all批量上傳文件實現(xiàn)代碼
客戶端
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);
});
}
});
}
});
服務(wù)端
<?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];
}
});
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
相關(guān)文章
詳解Anyscript開發(fā)指南繞過typescript類型檢查
這篇文章主要為大家介紹了詳解Anyscript開發(fā)指南繞過typescript類型檢查,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-09-09
JS常用正則表達(dá)式超全集(密碼強(qiáng)度校驗,金額校驗,IE版本,IPv4,IPv6校驗)
網(wǎng)上有很多關(guān)于JS常用正則表達(dá)式的文章很全但今天為大家分享一些最新,且非常有用的正則表達(dá)式其中有密碼強(qiáng)度校驗,金額校驗,IE版本,IPv4,IPv6校驗等2020-02-02

