我想调用嵌套函数并对返回的内部结果执行某些操作。
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值