thirdScriptError APP-SERVICE-SDK:setStorageSync:fail Error: Failed To Send Sync;at api getImageInfo success callback function Error: APP-SERVICE-SDK:setStorageSync:fail Error: Failed To Send Sync at setStorageSync ([publib]:1:538903) at r.(anonymous function ) ([publib]:1:540581) at Object._l.(anonymous function ) [as setStorageSync] ([publib]:1:541205) at Object.<anonymous> ([publib]:1:237550) at Object.<anonymous> ([publib]:1:778406) at Function.<anonymous> ([publib]:1:778536) at Object.<anonymous> ([publib]:1:228296) at success (weapp: ///app .js:45:14) at Function. function .o.(anonymous function ) ([publib]:1:777764) at Object.success ([publib]:1:101980) |
我想在程序启动时下载一个图片,然后缓存在本地,下次启动不用重复下载
调用了wx.getImageInfo方法,然后在success中想通过wx.setStirageSync以网络图片地址为key,下载好的res.path为value,存一个缓存
但是真机调试确报了这个错,是为什么??如何在本地缓存一张图片呢?
麻烦提供能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)
let imageUrl =
'https://www.baidu.com/img/bd_logo1.png?where=super'
console.log(
'下载前地址:'
+ imageUrl)
wx.getImageInfo({
src: imageUrl,
success: (res) => {
let localPath = res.path
console.log(
'下载后本地地址:'
+ localPath)
// 下面这行真机报错,模拟器不会有问题
wx.setStorageSync(imageUrl, localPath)
}
})
代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)提供下这个
https://developers.weixin.qq.com/s/EJR3mkma708P
只能真机才会出错
测试了下,没复现报错
你这是预览,不是通过IDE点击的真机调试,我发现实际上setStorageSync是存储数据了,但是会抛异常,就跟截图中的情况一样:
还是说getImageInfo这个方法微信内部已经做了图片缓存,文档里并没有描述出来 https://developers.weixin.qq.com/miniprogram/dev/api/wx.getImageInfo.html