这是在回调功能中不确定的

发布于 01-22 01:47 字数 1566 浏览 3 评论 0原文

我正在尝试使用AWS Amplify SDK将数据从Angular应用上传到S3。 该代码很简单并且有效,

await Storage.put(this.apkFileToUpload[0].name, this.apkFileToUpload[0], {
  progressCallback(progress) {
    console.log(`Uploaded: ${progress.loaded}/${progress.total}`);
  },
});

但我想向用户显示上传的进度。我在打字稿

uploadProgress = 0;

await Storage.put(this.apkFileToUpload[0].name, this.apkFileToUpload[0], {
  progressCallback(progress) {
    console.log(`Uploaded: ${progress.loaded}/${progress.total}`);
    this.uploadProgress =  (progress.loaded * 100) / progress.total;
  },
});

和html

          <div class="" style="margin: 0 auto; width: 180px; height: 180px">
            <div class="">
              <progressbar [value]="this.uploadProgress" type="warning" [striped]="true" style="height: 180px">{{ this.uploadProgress }}%</progressbar>
            </div>
          </div>

中添加了这个错误,但是我

ERROR TypeError: this is undefined
    progressCallback apk-release.component.ts:125
    put AWSS3Provider.js:279
    emit events.js:152
    progressChanged AWSS3ProviderManagedUpload.js:349
    setupEventListener AWSS3ProviderManagedUpload.js:343
    emit events.js:152
    onUploadProgress axios-http-handler.js:71
    Angular 14
    dispatchXhrRequest xhr.js:150
    ZoneAwarePromise Angular
    xhrAdapter xhr.js:11
    dispatchRequest dispatchRequest.js:59
    Angular 22
    digest webCryptoSha256.js:35
    Angular 35
    RxJS 5

怎么能从回调中获取数据并更新进度的价值?

I'm tryin to upload my data from my angular app to s3 using aws amplify sdk.
The code is simple and works

await Storage.put(this.apkFileToUpload[0].name, this.apkFileToUpload[0], {
  progressCallback(progress) {
    console.log(`Uploaded: ${progress.loaded}/${progress.total}`);
  },
});

But i want to show the progress of the upload to the user. I added in my typescript

uploadProgress = 0;

await Storage.put(this.apkFileToUpload[0].name, this.apkFileToUpload[0], {
  progressCallback(progress) {
    console.log(`Uploaded: ${progress.loaded}/${progress.total}`);
    this.uploadProgress =  (progress.loaded * 100) / progress.total;
  },
});

and my html

          <div class="" style="margin: 0 auto; width: 180px; height: 180px">
            <div class="">
              <progressbar [value]="this.uploadProgress" type="warning" [striped]="true" style="height: 180px">{{ this.uploadProgress }}%</progressbar>
            </div>
          </div>

But i got this error

ERROR TypeError: this is undefined
    progressCallback apk-release.component.ts:125
    put AWSS3Provider.js:279
    emit events.js:152
    progressChanged AWSS3ProviderManagedUpload.js:349
    setupEventListener AWSS3ProviderManagedUpload.js:343
    emit events.js:152
    onUploadProgress axios-http-handler.js:71
    Angular 14
    dispatchXhrRequest xhr.js:150
    ZoneAwarePromise Angular
    xhrAdapter xhr.js:11
    dispatchRequest dispatchRequest.js:59
    Angular 22
    digest webCryptoSha256.js:35
    Angular 35
    RxJS 5

How could i do to get my data and update the value of the progress from my callback ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花间憩2025-01-29 01:47:29

回调不正确

await Storage.put(this.apkFileToUpload[0].name, this.apkFileToUpload[0], {
  resumable: true,
  completeCallback: (event) => {
    console.log(`Successfully uploaded ${event.key}`);
    this.test();
    console.log(event);
    //We call the back end to notify that a new apk is available
  },
  progressCallback: (progress) => {
    console.log(`Uploaded: ${progress.loaded}/${progress.total}`);
    this.uploadProgress =  (progress.loaded * 100) / progress.total;
  },
  errorCallback: (err) => {
    console.error('Unexpected error while uploading', err);
  }
});

The callback was not correct

await Storage.put(this.apkFileToUpload[0].name, this.apkFileToUpload[0], {
  resumable: true,
  completeCallback: (event) => {
    console.log(`Successfully uploaded ${event.key}`);
    this.test();
    console.log(event);
    //We call the back end to notify that a new apk is available
  },
  progressCallback: (progress) => {
    console.log(`Uploaded: ${progress.loaded}/${progress.total}`);
    this.uploadProgress =  (progress.loaded * 100) / progress.total;
  },
  errorCallback: (err) => {
    console.error('Unexpected error while uploading', err);
  }
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文