欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

微信小程序 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)文章

最新評(píng)論