【问题标题】:Angular Promises Chaining SequentiallyAngular Promise 顺序链接
【发布时间】:2023-03-22 02:37:01
【问题描述】:

我正在使用 angular Upload 将文件上传到 Azure 存储。

 var filePath = [];
        Upload.upload({
            url: '/uploadFile',
            data: { file: $scope.selectedFile }
        }).then(function (resp) {
            //resp.data contains URL returned from upload
            filePath.push(resp.data);
        })

我需要执行3次文件上传,需要按顺序执行,例如:

upload [file 1], get [file 1] URL, 
upload [file 2], get [file 2] URL, 
upload [file 3], get [file 3] URL

file2 需要等待 file1 完成才能启动, 而file3需要等待file2完成才能启动,

如何使用 Promise 确保我以顺序模式获取文件 URL?

例如:filePath[file1URL, file2URL, file3URL]

【问题讨论】:

    标签: angularjs azure-storage angular-promise ng-file-upload


    【解决方案1】:

    你可以 var filePath = []; Upload.upload({ url: '/uploadFile', data: { file: $scope.selectedFile1 } }).then(function (resp) { filePath.push(resp.data); Upload.upload({ url: '/uploadFile', data: { file: $scope.selectedFile2 } }).then(function (resp) { filePath.push(resp.data); Upload.upload({... }) }) 确保您在上一个文件上传后上传。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-07-13
      • 1970-01-01
      • 2019-03-17
      • 1970-01-01
      • 1970-01-01
      • 2013-09-26
      • 2013-07-19
      相关资源
      最近更新 更多