微信小程序如何實現(xiàn)ES6Promise.all批量上傳文件

這篇文章主要介紹微信小程序如何實現(xiàn)ES6Promise.all批量上傳文件,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!

創(chuàng)新互聯(lián)公司是網(wǎng)站建設(shè)技術(shù)企業(yè),為成都企業(yè)提供專業(yè)的成都網(wǎng)站建設(shè)、網(wǎng)站建設(shè),網(wǎng)站設(shè)計,網(wǎng)站制作,網(wǎng)站改版等技術(shù)服務(wù)。擁有10多年豐富建站經(jīng)驗和眾多成功案例,為您定制適合企業(yè)的網(wǎng)站。10多年品質(zhì),值得信賴!

微信小程序 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];
  }
});

以上是“微信小程序如何實現(xiàn)ES6Promise.all批量上傳文件”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

網(wǎng)頁題目:微信小程序如何實現(xiàn)ES6Promise.all批量上傳文件
本文地址:http://muchs.cn/article24/ihiice.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)建站、網(wǎng)頁設(shè)計公司品牌網(wǎng)站建設(shè)、服務(wù)器托管靜態(tài)網(wǎng)站、網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

商城網(wǎng)站建設(shè)