NativeScript / NativeScript/plugins

[@nativescript/background-http] Error on uploading files

未关闭
#283 5 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
TypeScript
星标
206
派生
123
平均合并
2 天 1 小时
30 天内合并 PR
1

描述

Hello, after updating to newest NativeScript version, we're experiencing issues with file upload. It worked previously with NativeScript 6.

Packages:

"@nativescript/core": "^8.2.2",
"@nativescript/angular": "^13.0.3",
"@nativescript/background-http": "^6.0.0"

Upload config:

const request: Request = {
                url: this._getUrl(fileToUpload.addImageResponse),
                method: "PUT",
                headers: {
                    "Content-Type": "application/x-www-form-urlencoded",
                    "x-ms-blob-content-type": "image/jpeg",
                    "x-ms-blob-type": "BlockBlob"
                },
                description: "Uploading " + fileToUpload.fileName,
                androidAutoClearNotification: true,
                androidAutoDeleteAfterUpload: true
};

const task = this.session.uploadFile(fileToUpload.nativeFile.path, request);

task.on("progress", (e) => this._progressHandler(e as ProgressEventData, fileToUpload));
task.on("error", (e) => this._errorHandler(e as ErrorEventData, fileToUpload));
task.on("responded", this._respondedHandler);
task.on("complete", () => this._completeHandler(fileToUpload));
task.on("cancelled", this._cancelledHandler); // Android only

When executing, we're getting following error:

JS: ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'NotificationConfig' of undefined
JS: TypeError: Cannot read property 'NotificationConfig' of undefined
JS:     at setRequestOptions (file: src/webpack:/.../node_modules/@nativescript/background-http/index.android.js:247:0)
JS:     at getBinaryRequest (file: src/webpack:/.../node_modules/@nativescript/background-http/index.android.js:221:0)
JS:     at Function.create (file: src/webpack:/.../node_modules/@nativescript/background-http/index.android.js:152:0)
JS:     at Session.uploadFile (file: src/webpack:/.../node_modules/@nativescript/background-http/index.android.js:139:0)
JS:     at UploadService._uploadToCloud (file: src/webpack:/.../src/app/sl/services/upload/upload.service.ts:251:0)
JS:     at UploadService._checkAndUploadNextFile (file: src/webpack:/.../src/app/sl/services/upload/upload.service.ts:108:0)
JS:     at UploadService._checkAndPrepareNextFile (file: src/webpack:/.../src/app/sl/services/upload/upload.service.ts:97:0)
JS:     at file: src/webpack:/.../src/app/sl/services/upload/upload.service.ts:184:0
JS:     at _ZoneDelegate.in...

Tested on multiple Android devices with android versions from 10 to 12. Not sure if iOS has the same error. Any suggestions?

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

先查看 node_modules/@nativescript/background-http/index.android.js 中的堆栈跟踪,尤其是第 247 行的 setRequestOptions,然后检查 src/app/sl/services/upload/upload.service.ts 中大约位于第 97、108 和 251 行的 upload 调用。在 Android 上使用提供的软件包版本和 upload 配置重现该故障;当原因已确定且文件 upload 不再引发 NotificationConfig 错误时,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
android, typescript
领域
mobile
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
需要澄清
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。