2016-11-25 5 views
1

あなたは50以上の画像をcloundinaryにアップロードしようとしましたか?私は試してみましたが、約束は解決されません(.reflect()であっても)すべての画像をアップロードできません。アップロードの速度によっては、30%〜70%が失敗します。曇った複数の.jpgアップロードNODE.JS

完全にそれを非同期にすると、すべての画像が正しくアップロードされていることを確認する方法?私が使用しているモジュールのみがそのドキュメントからの青い鳥とcloudinaryモジュールです。

Promisebd = require('bluebird'); 
 

 
function uploadimg(img, i, itemId) { 
 
    var pubID = 'a2z/toys/' + itemId + '/' + i; 
 
    // return new cloudImg.v2.uploader.upload(img, { 
 
    return cloudinary.v2.uploader.upload(img, { // works 
 
    public_id: pubID, 
 
    quality: 90 
 
    // use_filename: true, 
 
    } , function(err, res){ 
 
    if(err) { 
 
     console.log(err); 
 
    } 
 
    console.log(res); 
 
    }); 
 
} 
 

 

 
promiseArr.push(uploadimg(fullimg, i, d[0].details.detailsProductId)); // pushing the promises to Arr 
 

 
    Promisebd.all(promiseArr.map(function(promise) { 
 
      return promise.reflect(); 
 
      })).each(function(inspection) { 
 
      if(inspection.isFulfilled()) { 
 
       console.log('The promise is the arr was fulfilled with ', inspection.value()); 
 
      }else{ 
 
       console.log('The promise is NOT the arr was NOT fulfilled with ', inspection.reason()); 
 
      } 
 
      })

答えて

1

はアップロードIMG機能をpromsifyとしてみてくださいそれを使用する

function uploadimgAsync(img, i, itemId) { 
    return new Promise(function (resolve, reject) { 
     var pubID = 'az/toys/' + itemId + '/' + i; 
     cloudinary.v2.uploader.upload(img, { // works 
      public_id: pubID, 
      quality: 90 
     }, 
     function(err, res){ 
      if(err) { 
       reject(err); 
      } 
      resolve(res); 
     }); 
    }); 
} 
関連する問題