NativeScript IOS: Photo uploads to server are randomly failing with slow networks(LTE 1 or 2 bars)
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 25/100
- Issue 类型
- 缺陷
- 描述清晰度
- 需要澄清
- 活跃度
- 停滞
- 技术栈
- angular, ios, typescript
- 领域
- api, mobile, networking
调研方向
先从提供的 uploadPhotos、submitPhoto 和 upload 代码片段开始,然后在 LTE 信号为 1–2 格的 iOS 17.2 上重现问题,同时检查 HttpErrorResponse 状态 0。将 forkJoin/zip 上传路径与强网络下的成功案例进行比较,并记录已验证的客户端或服务器端原因及修复方案。
由索引模型根据 Issue 内容生成。
描述
Nativescript version - 8.4.7, Angular 15, IOS 17.2
When uploading photos to server/Microsoft api in the slow network (LTE 1 or 2 bars). The photos are not uploading and returning below exception. Looks like the request is not even reaching the server.
error
{
"headers": {
"normalizedNames": {},
"lazyUpdate": null,
"headers": {}
},
"status": 0,
"statusText": "Unknown Error",
"url": "https://abc",
"ok": false,
"name": "HttpErrorResponse",
"message": "Http failure response for "https://abc": 0 Unknown Error",
"error": {}
}
When connected to a strong network LTE 3 or more bars ,5g or WIFI , I am able to upload more than 50 photos at once without any issues.
Here is my upload code
//component
uploadPhotos(): void {
let message;
this.parent = this.service.getPhotosToUpload();
if (this.parent !== null && this.parent.length > 0) {
const parentList$ = new Array<Observable<boolean[]>>;
this.parent.forEach(p=> {
const observable = this.submitPhoto(p)
if (observable) {
parentList$.push(observable);
}
});
zip(parentList$)
.pipe(
switchMap((flags: boolean[][], index: number) => {
let totalNotuploaded = 0;
let totalUploaded = 0;
const results =[]
flags.forEach((flag) => {
totalNotuploaded += flag.filter(falses => !falses).length;
totalUploaded += flag.filter(trues => trues).length;
});
results.push([totalNotuploaded, totalUploaded])
return of(results);
})
).subscribe((results: number[][]) => {
let notuploaded = results[0][0] ;
let uploaded = results[0][1];
this.message = `Uploaded ${uploaded} Photo(s).`;
if (notuploaded > 0) {
this.message += `Errors uploading ${notuploaded}`
}
});
} else {
this.message = `Uploaded 0 Photos.`;
}
}
submitPhoto(photo: PhotoWrapper): Observable<boolean[]> {
const photosToUpload$ = new Array<Observable<boolean>>();
const photosToUpload = photo.filter((filter) => !filter.Uploaded);
photosToUpload.forEach(photo => {
photo.FileContent = this.servic.getFileAsBase64String(new Path(photo.File.directory as any, photo.File.relativePath));
const observable = this.service.upload(photo);
photosToUpload$.push(
observable.pipe(
catchError(() => {
return of(null)
}),
switchMap((result: PhotoResult) => {
return of(result && result?.flag ? true : false)
})
));
});
if (photosToUpload$ && photosToUpload$.length) {
return forkJoin(photosToUpload$);
} else { return null; }
}
//upload service
upload(photosData: PhotoWrapper): Observable<PhotoResult> {
let headers = this.authService.getAuthHeader();
let url = this.configurationService.uploadPhotoUrl();
return this.http.post<boolean>(this.configurationService.uploadPhotoUrl(), photoDto, { headers: headers, observe: 'response' }).pipe(
map((result) =>( {flag: result.body, wrapper: photosData} as PhotoResult)),
);
}
}
can anyone help me on how to fix this issue or is there any setting on the ios/nativescript/angular side which will prevent this to happen or is something wrong with my upload code?
- 主要语言
- TypeScript
- 星标
- 206
- 派生
- 123
- 平均合并
- 2 天 1 小时
- 30 天内合并 PR
- 1
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
NativeScript/plugins 的其他 Issue
-
难度 1/5 1 小时以内 新手友好度 92/100
NativeScript/plugins#680 ·
-
难度 2/5 1-3 小时 新手友好度 82/100
NativeScript/plugins#671 ·
-
难度 1/5 1 小时以内 新手友好度 72/100
NativeScript/plugins#640 ·
-
难度 4/5 3-5 天 新手友好度 45/100
NativeScript/plugins#668 ·
-
难度 4/5 3-5 天 新手友好度 45/100
NativeScript/plugins#665 · 1 条评论 ·