Closed navychang closed 4 months ago
依赖云信lib 已更新至最新 0.6.0版本
代码
toUploadImg(path: string) { if (!path) return let check = IMPermissionUtil.checkPermissionsSync('ohos.permission.READ_MEDIA') let result: Record<string, boolean> = { 'isAllowed': check } let resultStr = JSON.stringify(result) nimLogger.d(toUploadImg:IMPermissionUtil resultStr == ${JSON.stringify(resultStr)}) // V2NIMStorageScene 默认头像类型景, 默认不过期 const sceneName = V2NIMStorageSceneConfig.DEFAULT_PROFILE().sceneName as string const task = NIMInitManager.getInstance() .nim.storageService?.createUploadFileTask({ filePath: path, sceneName: sceneName }) as V2NIMUploadFileTask NIMInitManager.getInstance() .nim.storageService?.uploadFile(task, (progress) => { nimLogger.d(toUploadImg:uploadFile == ${JSON.stringify(progress)}) }) .then(imgUrl => { if(imgUrl){ this.changeTeamAvatar(imgUrl) } nimLogger.d(toUploadImg:uploadFile then= ${JSON.stringify(values)}) }) .catch((err: Error) => { const body = err?err.message:"系统异常,请稍后再试!" IMToast.showToast(body) nimLogger.d(toUploadImg:uploadFile Error == ${JSON.stringify(err)}) nimLogger.d(toUploadImg:uploadFile Error.name == ${JSON.stringify(err.name)}) nimLogger.d(toUploadImg:uploadFile Error.stack == ${JSON.stringify(err.stack)}) nimLogger.d(toUploadImg:uploadFile Error.message == ${JSON.stringify(err.message)}) }); }
toUploadImg:IMPermissionUtil resultStr == ${JSON.stringify(resultStr)}
toUploadImg:uploadFile == ${JSON.stringify(progress)}
toUploadImg:uploadFile then= ${JSON.stringify(values)}
toUploadImg:uploadFile Error == ${JSON.stringify(err)}
toUploadImg:uploadFile Error.name == ${JSON.stringify(err.name)}
toUploadImg:uploadFile Error.stack == ${JSON.stringify(err.stack)}
toUploadImg:uploadFile Error.message == ${JSON.stringify(err.message)}
报错:
05-21 16:58:16.843 16449-16449 toUploadImg:uploadFile Error == {}
05-21 16:58:16.844 16449-16449 toUploadImg:uploadFile Error.name == "TypeError"
05-21 16:58:16.844 16449-16449 toUploadImg:uploadFile Error.stack == " at uploadFileTask (oh_modules/.ohpm/@nimsdk+core@hxfkkrvgslams3iczdzdusduyl0=/oh_modules/@nimsdk/core/src/main/ets/nim/storage/V2NIMStorageServiceImpl.js:1:4141)\n"
05-21 16:58:16.844 16449-16449 toUploadImg:uploadFile Error.message == "Cannot read property uploadState of undefined"
依赖云信lib 已更新至最新 0.6.0版本
代码
toUploadImg(path: string) { if (!path) return let check = IMPermissionUtil.checkPermissionsSync('ohos.permission.READ_MEDIA') let result: Record<string, boolean> = { 'isAllowed': check } let resultStr = JSON.stringify(result) nimLogger.d(
toUploadImg:IMPermissionUtil resultStr == ${JSON.stringify(resultStr)}
) // V2NIMStorageScene 默认头像类型景, 默认不过期 const sceneName = V2NIMStorageSceneConfig.DEFAULT_PROFILE().sceneName as string const task = NIMInitManager.getInstance() .nim.storageService?.createUploadFileTask({ filePath: path, sceneName: sceneName }) as V2NIMUploadFileTask NIMInitManager.getInstance() .nim.storageService?.uploadFile(task, (progress) => { nimLogger.d(toUploadImg:uploadFile == ${JSON.stringify(progress)}
) }) .then(imgUrl => { if(imgUrl){ this.changeTeamAvatar(imgUrl) } nimLogger.d(toUploadImg:uploadFile then= ${JSON.stringify(values)}
) }) .catch((err: Error) => { const body = err?err.message:"系统异常,请稍后再试!" IMToast.showToast(body) nimLogger.d(toUploadImg:uploadFile Error == ${JSON.stringify(err)}
) nimLogger.d(toUploadImg:uploadFile Error.name == ${JSON.stringify(err.name)}
) nimLogger.d(toUploadImg:uploadFile Error.stack == ${JSON.stringify(err.stack)}
) nimLogger.d(toUploadImg:uploadFile Error.message == ${JSON.stringify(err.message)}
) }); }报错:
05-21 16:58:16.843 16449-16449 toUploadImg:uploadFile Error == {}
05-21 16:58:16.844 16449-16449 toUploadImg:uploadFile Error.name == "TypeError"
05-21 16:58:16.844 16449-16449 toUploadImg:uploadFile Error.stack == " at uploadFileTask (oh_modules/.ohpm/@nimsdk+core@hxfkkrvgslams3iczdzdusduyl0=/oh_modules/@nimsdk/core/src/main/ets/nim/storage/V2NIMStorageServiceImpl.js:1:4141)\n"
05-21 16:58:16.844 16449-16449 toUploadImg:uploadFile Error.message == "Cannot read property uploadState of undefined"