HarmonyOS 鸿蒙Next 选择图片上传,调用request.uploadFile 接口,app闪退
HarmonyOS 鸿蒙Next 选择图片上传,调用request.uploadFile 接口,app闪退 选择图片上传,调用request.uploadFile 接口,app闪退
以下是代码
代码执行到箭头那里,就不往下在执行了。
7 回复
10-23 21:25:58.458 18026-21641/com.example.dangquntong E 01300/Appkit: [js_ability_stage.cpp(Init:133)]AbilityStageObj is nullptr
10-23 21:25:58.458 18026-21641/com.example.dangquntong W 01300/Appkit: [js_ability_stage.cpp(OnCreate:178)]Not found AbilityStage.js
10-23 21:25:58.471 18026-21641/com.example.dangquntong E 01300/Runtime: [js_runtime.cpp(LoadModule:688)]Failed to make module file path: /data/storage/el1/bundle/entry/ets/entryability/EntryAbility.abc
10-23 21:25:58.476 18026-21641/com.example.dangquntong W 03900/NAPI: [native_module_manager.cpp(LoadModuleLibrary)] dlopen failed: dlopen failed: library "/system/lib64/module/libdisplay.z.so" not found
10-23 21:25:58.478 18026-21641/com.example.dangquntong E 03F00/ArkCompiler: [debugger] GenerateCallFrame: Unknown url: /mnt/disk/jenkins/ci/workspace/chipset_pipeline_release/china_compile/component_code/foundation/ability/ability_runtime/frameworks/js/napi/ability/ability.js
10-23 21:25:58.478 18026-21641/com.example.dangquntong E 03F00/ArkCompiler: [debugger] NotifyPaused: GenerateCallFrames failed
10-23 21:26:00.611 18026-21641/com.example.dangquntong E 01300/Ability: [ability.cpp(HandleCreateAsRecovery:1029)]AppRecovery not recovery restart
10-23 21:26:00.612 18026-21641/com.example.dangquntong E 01300/Ability: [ability.cpp(InitWindow:1636)]Ability::InitWindow abilityWindow_ is nullptr
10-23 21:26:00.635 18026-21641/com.example.dangquntong E LOGLIMIT/: process dangquntong drop log, threshold:13050
10-23 21:26:00.741 18026-21641/com.example.dangquntong E OHOS_LIBC_ADAPTOR/: sem_close is not supported on bionic
10-23 21:26:00.758 18026-21662/com.example.dangquntong E 02C02/PARAM: [param_comm.c:140]Forbid to access parameter persist.sys.graphic.animationscale
10-23 21:26:00.758 18026-21662/com.example.dangquntong E 02C02/PARAM: [param_request.c:255]Forbid to watch parameter persist.sys.graphic.animationscale
10-23 21:26:00.783 18026-21641/com.example.dangquntong E 02C02/PARAM: [param_comm.c:140]Forbid to access parameter persist.sys.arkui.animationscale
10-23 21:26:00.783 18026-21641/com.example.dangquntong E 02C02/PARAM: [param_request.c:255]Forbid to watch parameter persist.sys.arkui.animationscale
10-23 21:26:01.079 18026-21669/com.example.dangquntong E 02C02/PARAM: [param_comm.c:140]Forbid to access parameter debug.graphic.frame
10-23 21:26:01.079 18026-21669/com.example.dangquntong E 02C02/PARAM: [param_request.c:255]Forbid to watch parameter debug.graphic.frame
10-23 21:26:01.079 18026-21669/com.example.dangquntong E 01400/OHOS::ROSEN: print log error in vsprintf_s
10-23 21:26:01.079 18026-21669/com.example.dangquntong E 02C02/PARAM: [param_comm.c:140]Forbid to access parameter debug.graphic.overdraw
10-23 21:26:01.079 18026-21669/com.example.dangquntong E 02C02/PARAM: [param_request.c:255]Forbid to watch parameter debug.graphic.overdraw
10-23 21:26:01.079 18026-21669/com.example.dangquntong E 02C02/PARAM: [param_comm.c:140]Forbid to access parameter debug.graphic.colors_overdraw
10-23 21:26:01.080 18026-21669/com.example.dangquntong E 02C02/PARAM: [param_request.c:255]Forbid to watch parameter debug.graphic.colors_overdraw
10-23 21:26:01.223 18026-21641/com.example.dangquntong E LOGLIMIT/: process dangquntong drop log, threshold:13050
10-23 21:26:01.409 18009-18009/com.example.dangquntong W InputMethodManager/: startInputReason = 9
10-23 21:26:01.415 18009-18009/com.example.dangquntong W HwRemoteInputMethodManager/: isCasting false because IHwDistributedWindowManager is invalid.
10-23 21:26:04.101 18026-21641/com.example.dangquntong W 02800/TimeCostChk: in ~TimeCostChk, Time cost overtime (9018,(us)>300(us)) when Reason:ClientMsgHandler::OnMsgHandler,chk:overtime 300(us),param1:11,param2:0
10-23 21:26:04.101 18026-21641/com.example.dangquntong W 03900/Ace: [rosen_render_context.cpp(ClearFocusState)-(0)] focusStateModifier_ is null, return on line 1083
10-23 21:26:04.235 18026-21641/com.example.dangquntong W 02800/TimeCostChk: in ~TimeCostChk, Time cost overtime (339,(us)>300(us)) when Reason:ClientMsgHandler::OnMsgHandler,chk:overtime 300(us),param1:11,param2:0
10-23 21:26:04.362 18026-21686/com.example.dangquntong E LOGLIMIT/: process dangquntong drop log, threshold:13050
10-23 21:26:05.822 18026-21655/com.example.dangquntong E LOGLIMIT/: process dangquntong drop log, threshold:13050
10-23 21:26:06.030 18026-21641/com.example.dangquntong W 03F00/ArkCompiler: [debugger] NotifyScriptParsed: already loaded: entry/src/main/ets/pages/uploadfile.ets
10-23 21:26:06.032 18026-21641/com.example.dangquntong W 03900/Ace: [rosen_render_context.cpp(ClearFocusState)-(0)] focusStateModifier_ is null, return on line 1083
10-23 21:26:06.033 18026-21641/com.example.dangquntong W 03900/Ace: [text_field_pattern.cpp(UpdateCaretPosition)-(0)] Not on focus, cannot update caret
10-23 21:26:06.033 18026-21641/com.example.dangquntong W 03900/Ace: [text_field_pattern.cpp(UpdateCaretPosition)-(0)] Not on focus, cannot update caret
10-23 21:26:06.037 18026-21641/com.example.dangquntong W 03900/Ace: [text_field_pattern.cpp(UpdateCaretPosition)-(0)] Not on focus, cannot update caret
10-23 21:26:06.037 18026-21641/com.example.dangquntong W 03900/Ace: [text_field_pattern.cpp(UpdateCaretPosition)-(0)] Not on focus, cannot update caret
10-23 21:26:06.051 18026-21672/com.example.dangquntong E 03900/Ace: [image_loader.cpp(CreateImageLoader)-(0)] Image source type not supported! srcType: -1, sourceInfo: empty source
10-23 21:26:06.057 18026-21641/com.example.dangquntong W 03900/Ace: [text_field_pattern.cpp(UpdateCaretPosition)-(0)] Not on focus, cannot update caret
10-23 21:26:06.058 18026-21641/com.example.dangquntong W 03900/Ace: [text_field_pattern.cpp(UpdateCaretPosition)-(0)] Not on focus, cannot update caret
10-23 21:26:06.102 18026-21669/com.example.dangquntong E LOGLIMIT/: process dangquntong drop log, threshold:13050
10-23 21:26:09.517 18026-21641/com.example.dangquntong W 02800/TimeCostChk: in ~TimeCostChk, Time cost overtime (5820,(us)>300(us)) when Reason:ClientMsgHandler::OnMsgHandler,chk:overtime 300(us),param1:11,param2:0
10-23 21:26:09.517 18026-21641/com.example.dangquntong W 03900/Ace: [rosen_render_context.cpp(ClearFocusState)-(0)] focusStateModifier_ is null, return on line 1083
10-23 21:26:09.617 18026-21641/com.example.dangquntong W 02800/TimeCostChk: in ~TimeCostChk, Time cost overtime (322,(us)>300(us)) when Reason:ClientMsgHandler::OnMsgHandler,chk:overtime 300(us),param1:11,param2:0
10-23 21:26:10.682 18009-18009/com.example.dangquntong E ple/.dangqunton: logPower_buf_write not support
10-23 21:26:10.682 18009-18009/com.example.dangquntong W HwApsImpl/: not support full screen video recognize feature ## com.example.dangquntong
10-23 21:26:10.685 18009-18027/com.example.dangquntong E BufferQueueProducer/: [SurfaceView[com.example.dangquntong/EntryAbility]#1(BLAST Consumer)1](id:465900000001,api:1,p:18026,c:18009) cancelBuffer: BufferQueue has been abandoned
10-23 21:26:10.707 18009-18009/com.example.dangquntong W SurfaceView/: ViewUI notifySurfaceDestroyed
10-23 21:26:10.707 18009-18009/com.example.dangquntong W SurfaceView/: ViewUI notifySurfaceDestroyed
10-23 21:26:10.763 18009-18009/com.example.dangquntong W SurfaceView/: ViewUI notifySurfaceDestroyed
10-23 21:26:11.630 18026-21641/com.example.dangquntong E 03900/Ace: [jsi_declarative_engine.cpp(CallAppFunc)-(0)] property "default" is not a object
10-23 21:26:11.630 18026-21641/com.example.dangquntong W 03900/Ace: [rosen_render_context.cpp(ClearFocusState)-(0)] focusStateModifier_ is null, return on line 1083
10-23 21:26:11.630 18026-21641/com.example.dangquntong W 03900/Ace: [overlay_manager.cpp(HideAllMenus)-(0)] OverlayManager: menuMap is empty
10-23 21:26:11.630 18026-21641/com.example.dangquntong W 03900/Ace: [overlay_manager.cpp(HideAllPopups)-(0)] OverlayManager: popupMap is empty
10-23 21:26:11.638 18026-21641/com.example.dangquntong E 03900/Ace: [jsi_declarative_engine.cpp(CallAppFunc)-(0)] property "default" is not a object
10-23 21:26:11.671 18026-21641/com.example.dangquntong W 03900/Ace: [flutter_ace_view.cpp(SurfaceChanged)-(-1)] pipelineContext is null, return on line 439
10-23 21:26:12.710 18009-18009/com.example.dangquntong W SurfaceView/: ViewUI notifySurfaceDestroyed
10-23 21:26:12.679 18009-18009/com.example.dangquntong E 02D03/HiTraceC: HiTraceEnd error: invalid thread id.
10-23 21:26:12.822 18009-18009/com.example.dangquntong E ple/.dangqunton: logPower_buf_write not support
10-23 21:26:12.828 18009-18009/com.example.dangquntong E ple/.dangqunton: logPower_buf_write not support
10-23 21:26:12.828 18009-18009/com.example.dangquntong W HwApsImpl/: not support full screen video recognize feature ## com.example.dangquntong
10-23 21:26:12.884 18009-18009/com.example.dangquntong W InputMethodManager/: startInputReason = 1
10-23 21:26:12.886 18009-18009/com.example.dangquntong W HwRemoteInputMethodManager/: isCasting false because IHwDistributedWindowManager is invalid.
10-23 21:26:18.238 18026-21645/com.example.dangquntong E 01300/Ability: [app_recovery.cpp(ScheduleSaveAppState:84)]AppRecovery ScheduleSaveAppState. is not enabled
10-23 21:26:18.238 18026-21645/com.example.dangquntong E 01300/Ability: [app_recovery.cpp(ScheduleRecoverApp:118)]AppRecovery ScheduleRecoverApp. is not enabled
10-23 21:26:18.453 18026-21642/com.example.dangquntong E 01510/BinderConnector: 139: <private>:ioctl_binder returned EINTR
10-23 21:26:18.454 18026-21643/com.example.dangquntong E 01510/BinderConnector: 139: <private>:ioctl_binder returned EINTR
10-23 21:26:18.459 18026-21646/com.example.dangquntong E 01510/BinderConnector: 139: <private>:ioctl_binder returned EINTR
10-23 21:26:20.714 18026-21642/com.example.dangquntong E 01510/BinderConnector: 139: <private>:ioctl_binder returned EINTR
10-23 21:26:20.714 18026-21646/com.example.dangquntong E 01510/BinderConnector: 139: <private>:ioctl_binder returned EINTR
10-23 21:26:20.715 18026-21643/com.example.dangquntong E 01510/BinderConnector: 139: <private>:ioctl_binder returned EINTR
10-23 21:26:20.737 18026-21641/com.example.dangquntong E 03900/Ace: [jsi_declarative_engine.cpp(CallAppFunc)-(0)] property "default" is not a object
10-23 21:26:20.740 18026-21641/com.example.dangquntong W 02800/TimeCostChk: in ~TimeCostChk, Time cost overtime (2574,(us)>300(us)) when Reason:ClientMsgHandler::OnMsgHandler,chk:overtime 300(us),param1:11,param2:0
10-23 21:26:20.741 18026-21641/com.example.dangquntong W 03900/Ace: [rosen_render_context.cpp(ClearFocusState)-(0)] focusStateModifier_ is null, return on line 1083
更多关于HarmonyOS 鸿蒙Next 选择图片上传,调用request.uploadFile 接口,app闪退的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
Device info: OpenHarmony 3.2
Build info: OpenHarmony 3.2.9.1
Module name: com.example.dangquntong
Version: 1.0.0
Pid: 19929
Uid: 20040004
Reason: Signal: SIGABRT(SI_QUEUE)@0x0131c94400004dd9 from:19929:20040004
LastFatalMessage:
Thread name: com.example.dan
#00 pc 000000000009fcbf /vendor/aosp/system/lib64/libc.so(abort+191) (2de37b8aa6e96dd64a6cfa51bd78ae6e)
#01 pc 000000000010ff17 /system/lib64/libc++.so (b0558bc452cf6af82d54d8a4a5753b5d9a038edd)
#02 pc 00000000000ecb36 /system/lib64/libc++.so (b0558bc452cf6af82d54d8a4a5753b5d9a038edd)
#03 pc 000000000010e471 /system/lib64/libc++.so (b0558bc452cf6af82d54d8a4a5753b5d9a038edd)
#04 pc 0000000000113675 /system/lib64/libc++.so (b0558bc452cf6af82d54d8a4a5753b5d9a038edd)
#05 pc 00000000001135cc /system/lib64/libc++.so(__cxa_throw+172) (b0558bc452cf6af82d54d8a4a5753b5d9a038edd)
#06 pc 000000000009470b /system/lib64/libc++.so(std::__h::stol(std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>> const&, unsigned long*, int)+363) (b0558bc452cf6af82d54d8a4a5753b5d9a038edd)
#07 pc 000000000000d42b /system/lib64/libupload_lib.z.so (db411fe02e0de4c4a073f1029d88926b)
#08 pc 000000000000c847 /system/lib64/libupload_lib.z.so (db411fe02e0de4c4a073f1029d88926b)
#09 pc 0000000000061683 /system/lib64/libcurl_shared.z.so (e44ad4c1542f8e4681da2dd58508cde2)
#10 pc 0000000000047283 /system/lib64/libcurl_shared.z.so (e44ad4c1542f8e4681da2dd58508cde2)
#11 pc 0000000000072e56 /system/lib64/libcurl_shared.z.so (e44ad4c1542f8e4681da2dd58508cde2)
#12 pc 000000000005908f /system/lib64/libcurl_shared.z.so (e44ad4c1542f8e4681da2dd58508cde2)
#13 pc 000000000005834d /system/lib64/libcurl_shared.z.so(curl_multi_perform+173) (e44ad4c1542f8e4681da2dd58508cde2)
#14 pc 000000000000c167 /system/lib64/libupload_lib.z.so (db411fe02e0de4c4a073f1029d88926b)
#15 pc 000000000000bd6e /system/lib64/libupload_lib.z.so (db411fe02e0de4c4a073f1029d88926b)
#16 pc 0000000000012aa2 /system/lib64/libupload_lib.z.so (db411fe02e0de4c4a073f1029d88926b)
#17 pc 000000000001230c /system/lib64/libupload_lib.z.so (db411fe02e0de4c4a073f1029d88926b)
#18 pc 000000000001207b /system/lib64/libupload_lib.z.so (db411fe02e0de4c4a073f1029d88926b)
#19 pc 00000000000152b8 /system/lib64/libupload_lib.z.so (db411fe02e0de4c4a073f1029d88926b)
#20 pc 0000000000108e1a /vendor/aosp/system/lib64/libc.so(__pthread_start(void*)+58) (2de37b8aa6e96dd64a6cfa51bd78ae6e)
#21 pc 00000000000a1477 /vendor/aosp/system/lib64/libc.so(__start_thread+55) (2de37b8aa6e96dd64a6cfa51bd78ae6e)
先确认下,是否授权了 ohos.permission.INTERNET
其次,把报错的日志打印出来看下。
望采纳答案!
找HarmonyOS工作还需要会Flutter的哦,有需要Flutter教程的可以学学大地老师的教程,很不错,B站免费学的哦:https://www.bilibili.com/video/BV1S4411E7LY/?p=17
async selectImage() {
try {
let PhotoSelectOptions = new picker.PhotoSelectOptions();
PhotoSelectOptions.MIMEType = picker.PhotoViewMIMETypes.IMAGE_TYPE;
PhotoSelectOptions.maxSelectNumber = 2;
let photoPicker = new picker.PhotoViewPicker();
photoPicker.select(PhotoSelectOptions).then((PhotoSelectResult) => {
console.info('xx PhotoViewPicker.select successfully, PhotoSelectResult uri: ' + JSON.stringify(PhotoSelectResult));
// 从图库选择图片后,返回图片uri
let uri = PhotoSelectResult.photoUris[0];
console.info('xx uri:' + uri)
this.imgSrc = uri
// 读取上面返回uri
let file = fs.openSync(uri, fs.OpenMode.CREATE);
// 复制文件到缓存目录下
fs.copyFileSync(file.fd, cacheDir + '/test.jpg')
// 上传文件到服务器上
this.uploadImage()
}).catch((err) => {
console.error('xx PhotoViewPicker.select failed with err: ' + err);
});
} catch (err) {
console.error('xx PhotoViewPicker failed with err: ' + err);
}
}
uploadImage() {
// 将本地应用文件上传至网络服务器
try {
request.uploadFile(context, uploadConfig)
.then((uploadTask) => {
// uploadTask.on('fail', (taskStates) => {
// for (let i = 0; i < taskStates.length; i++) {
// console.info("upOnFail taskState:" + JSON.stringify(taskStates[i]));
// };
// })
uploadTask.on('complete', (taskStates) => {
for (let i = 0; i < taskStates.length; i++) {
console.info(`xx upload complete taskState: ${JSON.stringify(taskStates[i])}`);
this.message = JSON.stringify(taskStates[i])
}
});
}).catch((err) => {
console.error(`xx Invoke uploadFile failed, code is ${err.code}, message is ${err.message}`);
this.message = err.message
})
} catch (err) {
console.error(`xx Invoke uploadFile failed, code is ${err.code}, message is ${err.message}`);
this.message = err.message
}
}
怎么定义的呢,
针对HarmonyOS鸿蒙系统中,在Next版本下进行图片上传并调用request.uploadFile
接口导致app闪退的问题,可能的原因及解决方案如下:
-
权限问题:
- 确保应用已正确申请并获得了存储访问权限,特别是读写外部存储的权限。检查
manifest.json
或相应的权限配置文件,确保READ_EXTERNAL_STORAGE
和WRITE_EXTERNAL_STORAGE
权限已声明。
- 确保应用已正确申请并获得了存储访问权限,特别是读写外部存储的权限。检查
-
文件路径问题:
- 验证传递给
request.uploadFile
的文件路径是否正确。路径错误或文件不存在会导致上传失败,进而可能引发闪退。
- 验证传递给
-
接口使用不当:
- 检查
request.uploadFile
的调用方式是否符合鸿蒙系统的API规范。确保所有必要的参数都已正确传递,特别是文件路径、上传服务器的URL等。
- 检查
-
内存管理:
- 考虑是否存在内存泄漏或资源未正确释放的情况。大文件上传可能消耗大量内存,确保应用有适当的内存管理机制。
-
系统兼容性:
- 确认当前鸿蒙系统版本是否支持你使用的API。不同版本的鸿蒙系统可能有所不同,查阅官方文档确认兼容性。
如果问题依旧没法解决请联系官网客服,官网地址是 https://www.itying.com/category-93-b0.html,