提问人:MigboyDev 提问时间:8/23/2023 更新时间:8/23/2023 访问量:20
由于卡巴斯基安全软件,文件上传在上传结束前达到 100%
File upload reaches 100% before upload end, due to Kapersky Internet Security
问:
我正在将 Angular 与 NodeJs API 一起使用。我实现了一种通过上传进度跟踪将文件上传到 api 的方法。
起初,我使用了 HttpClient 服务的 reportProgress 和 observe 属性,但在每次上传时,尽管上传未完成,但发出的第一个事件会自动返回 100%。是这样的:
uploadMedia(file: File, type: string, description: string): Observable<any> {
const formdata: FormData = new FormData();
formdata.append("file", file);
formdata.append("type", type);
formdata.append("description", description);
return this.httpClient.post<MediaFile>(`${this.apiUrl}files/single-file`, formdata, {
reportProgress: true,
observe: "events",
});
}
然后,由于这不起作用,我浏览了软件包。我测试了“@kbob/ng2-file-upload”和“ngx-uploadx”,但仍然有同样的问题。也就是说,在线或本地,无论文件重量是 1MB 还是 100MB,我都会自动获得 100% 的进度,因此我必须等到上传实际完成。但是,在我咨询的所有演示或教程中,进度百分比都非常完美。 最后,我使用 AJAX 测试了第三种方法。像这样的东西:
uploadPosterFile(uploadEvent: any): void {
this.xhrUploader = new XMLHttpRequest();
this.abortButtonLocked = false;
this.progressActive = true;
this._detector.markForCheck()
this.xhrUploader.upload.onprogress = (progressEvent) => {
let percentage = ((progressEvent.loaded / progressEvent.total) * 100).toFixed(2);
this.uploadProgress = Number(percentage);
this._detector.markForCheck()
};
this.xhrUploader.upload.onloadend = (end) => {
this.abortButtonLocked = true;
this._detector.markForCheck()
}
this.xhrUploader.onreadystatechange = () => {
if (this.xhrUploader.readyState === 4 && this.xhrUploader.status === 200) {
this.getTicketImg(JSON.parse(this.xhrUploader.responseText))
}
};
this.xhrUploader.upload.onabort = () => {
this.ticket.posterFile = undefined;
this.abortButtonLocked = false;
this.progressActive = false;
this.uploadProgress = 0;
this._alertService.showToast('Upload canceled', 'info', 'bottom-center');
this._detector.markForCheck()
}
this.xhrUploader.upload.onerror = () => {
this.ticket.posterFile = undefined;
this.abortButtonLocked = false;
this.progressActive = false;
this.uploadProgress = 0;
this._alertService.showToast(`Failed Upload! Please check your network connexion.`, 'error', 'bottom-center', 3200);
this._detector.markForCheck()
}
this.xhrUploader.open('POST', `${this.apiUrl}files/single-file`);
let formData = new FormData();
formData.append("file", uploadEvent.target.files[0]);
this.xhrUploader.send(formData);
this._detector.markForCheck()
}
结果又是一样的。我有一个想法,停用我的防病毒软件(卡巴斯基互联网安全软件)并繁荣!一切都很好。因此,我正在寻找一种解决方案,允许我解决这个问题,因为我仍然不会要求所有使用防病毒软件的用户停用它们。
答: 暂无答案
评论