NativeScript / NativeScript/plugins
[@nativescript/background-http] Error on uploading files
未關閉
還沒有人認領這個 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?
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 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