这是在回调功能中不确定的
我正在尝试使用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 技术交流群。

回调不正确
The callback was not correct