如何以递归方式返回嵌套promise的结果

时间:2016-07-31 17:01:48

标签: javascript

我想调用嵌套函数并对返回的内部结果执行某些操作。

uploadVideoFile(file, bucketName, fileName) {

    I want to do something with progresssUpdate values here.

}



export function uploadVideoFile(file, bucketName, fileName){
    var s3bucket = new AWS.S3();
    return new Promise ((resolve, reject) => {
      return s3bucket.createBucket(() => {
          var params = {Bucket: bucketName, Key: fileName, Body: file};
          return s3bucket.putObject(params, (err, data) => {
              if (err) {
                 reject('error');
                  console.log('Error uploading data: ', err);
               }
               else
                 resolve('success');
                  console.log('Successfully uploaded data to bucket/sub-bucket/');
          }).on('httpUploadProgress', progress => {
               let progresssUpdate = Math.round(progress.loaded / progress.total * 100);
               return progresssUpdate;
          });
      });
    });
 }

正如您所看到的,返回的最后一个值是progresssUpdate,它在循环中运行,直到我的文件上传完成。

如何从主函数

获取内部progresssUpdate值

0 个答案:

没有答案