【问题标题】:cloudinary multiple .jpg uploads NODE.JScloudinary 多个 .jpg 上传 NODE.JS
【发布时间】:2017-04-10 04:33:50
【问题描述】:

你们中有人尝试将 50 多张图片上传到 cloundinary 吗?我一直在尝试,但问题是 promise 没有得到解决(即使使用 .reflect() 并且无法上传所有图像。根据上传速度,它将失败 30% ~ 70%。

有什么方法可以让它完全异步并确保所有图片都正确上传?我使用的唯一模块是他们文档中的 bluebird 和 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());
            }
          })

【问题讨论】:

    标签: node.js express bluebird cloudinary


    【解决方案1】:

    promsify 你的上传 img 功能并尝试使用它

    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);   
            }); 
        });   
    }
    

    【讨论】:

      猜你喜欢
      • 2019-01-05
      • 2021-02-01
      • 2017-12-02
      • 2021-04-07
      • 2020-04-07
      • 2019-05-11
      • 2021-01-24
      • 2016-04-28
      • 2015-09-16
      相关资源
      最近更新 更多