微信小程序 ES6Promise.all批量上傳文件實(shí)現(xiàn)代碼
更新時(shí)間:2017年04月14日 15:13:45 作者:馬小云
這篇文章主要介紹了微信小程序 ES6Promise.all批量上傳文件實(shí)現(xiàn)代碼的相關(guān)資料,需要的朋友可以參考下
微信小程序 ES6Promise.all批量上傳文件實(shí)現(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];
}
});
感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!
相關(guān)文章
關(guān)于JavaScript?中?if包含逗號(hào)表達(dá)式
這篇文章主要介紹了?關(guān)于JavaScript?中?if包含逗號(hào)表達(dá)式,有時(shí)會(huì)看到JavaScript中if判斷里包含英文逗號(hào)?“,”,這個(gè)是其實(shí)是逗號(hào)表達(dá)式。在if條件里,只有最后一個(gè)表達(dá)式起判斷作用。下面來看看文章的具體介紹吧2021-11-11
微信小程序網(wǎng)絡(luò)請(qǐng)求wx.request詳解及實(shí)例
這篇文章主要介紹了微信小程序網(wǎng)絡(luò)請(qǐng)求wx.request詳解及實(shí)例的相關(guān)資料,需要的朋友可以參考下2017-05-05
微信小程序 跳轉(zhuǎn)傳遞數(shù)據(jù)的實(shí)例
這篇文章主要介紹了微信小程序 跳轉(zhuǎn)傳遞數(shù)據(jù)的實(shí)例的相關(guān)資料,需要的朋友可以參考下2017-07-07
微信小程序 基礎(chǔ)知識(shí)css樣式media標(biāo)簽
這篇文章主要介紹了微信小程序 基礎(chǔ)知識(shí)css樣式media標(biāo)簽的相關(guān)資料,需要的朋友可以參考下2017-02-02
JavaScript+HTML實(shí)現(xiàn)學(xué)生信息管理系統(tǒng)
這篇文章主要介紹了JavaScript實(shí)現(xiàn)學(xué)生信息管理系統(tǒng),文中有非常詳細(xì)的代碼示例,對(duì)正在學(xué)習(xí)js的小伙伴們有一定的幫助,需要的朋友可以參考下2021-04-04

