0

I want to call a nested function and do something with the inner results returned.

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

As you can see the last value returned is progresssUpdate which runs in a loop until my file upload is complete.

How do I get the inner progresssUpdate values from my main function

user1526912
  • 15,818
  • 14
  • 57
  • 92
  • This might help: http://stackoverflow.com/questions/14182778/how-to-get-returned-value-by-function-with-callback-inside – Rajesh Jul 31 '16 at 17:03
  • This question isnt necessarily a duplicate. Quentin , have you even read or try to understand what I am trying to do. First of all I am using pure promises. The question that you stated as duplicate is referring to using Ajax and promises combined. So easy for you guys to flag questions as duplicates... – user1526912 Jul 31 '16 at 19:09
  • "*How do I get the inner progresssUpdate values*" - Use a callback. You cannot `return` from an asynchronous callback - just like you cannot `return "success"` from the `putObject` callback. – Bergi Jul 31 '16 at 20:53
  • @user1526912 its not an exact duplicate, but ajax and promise are both async and only way to get data is callback. So I guess answers in that post will point you in right direction. – Rajesh Aug 01 '16 at 06:58

0 Answers0