HSP调用getRawFileContent失败?

使用代码:

getContext(this).resourceManager.getRawFileContent('test.json')
.then(res=>{
  console.log('xx' + res.toString())
}).catch((error:BusinessError) =>{
  console.log(`xx error ${JSON.stringify(error)}`);
})

报错信息:

{“code”:9001005,“message”:“GetRawFileContent failed”}
阅读 1.1k
1 个回答

HSP模块中默认获取的context为entry的context,需要创建moduleContext获取当前HSP模块的context。

参考代码:

getContext(this).createModuleContext('sharedLibrary').resourceManager.getRawFileContent('test.json')
.then(res=>{
  console.log(res.toString())
}).catch((error:BusinessError) =>{
  console.log(`error ${JSON.stringify(error)}`);
})
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进