plus.io.resolveLocalFileSystemURL("/storage/emulated/0/Download/QQ/test.json", function(entry) {
entry.file(function(file) {
let fileReader = new plus.io.FileReader();
fileReader.readAsText(file, 'utf-8');
fileReader.onerror = function(err) {
uni.showToast({
title: "读取文件失败",
icon: "none"
})
console.log("读取文件失败", err);
}
fileReader.onloadend = function(e) {
if (e.target.result && e.target.result.length !== 0) {
let importData = JSON.parse(e.target.result);
savePsdBatch(importData);
}
}
})
}, error => {
console.log("请求文件系统失败", error);
})
- 发布:2024-12-05 17:08
- 更新:2024-12-05 17:16
- 阅读:56
产品分类: HTML5+
HBuilderX版本号: 4.36
手机系统: Android
手机系统版本号: Android 10
手机厂商: 小米
手机机型: xiaomi8
打包方式: 云端
操作步骤:
预期结果:
正确读取文件数据
正确读取文件数据
实际结果:
{
"type": "error",
"bubbles": false,
"cancelBubble": false,
"cancelable": false,
"lengthComputable": false,
"loaded": 0,
"total": 0,
"target": {
"fileName": "/storage/emulated/0/Download/QQ/test.json",
"readyState": 2,
"result": null,
"error": {
"code": 10,
"message": "执行出错"
},
"onloadstart": null,
"onprogress": null,
"onload": null,
"onabort": null,
"onerror": "function() { [native code] }",
"onloadend": "function() { [native code] }"
}
}
{
"type": "error",
"bubbles": false,
"cancelBubble": false,
"cancelable": false,
"lengthComputable": false,
"loaded": 0,
"total": 0,
"target": {
"fileName": "/storage/emulated/0/Download/QQ/test.json",
"readyState": 2,
"result": null,
"error": {
"code": 10,
"message": "执行出错"
},
"onloadstart": null,
"onprogress": null,
"onload": null,
"onabort": null,
"onerror": "function() { [native code] }",
"onloadend": "function() { [native code] }"
}
}
bug描述:
plus.io.resolveLocalFileSystemURL("/storage/emulated/0/Download/QQ/test.json", function(entry) {
entry.file(function(file) {
let fileReader = new plus.io.FileReader();
fileReader.readAsText(file, 'utf-8');
fileReader.onerror = function(err) {
uni.showToast({
title: "读取文件失败",
icon: "none"
})
console.log("读取文件失败", err);
}
fileReader.onloadend = function(e) {
if (e.target.result && e.target.result.length !== 0) {
let importData = JSON.parse(e.target.result);
savePsdBatch(importData);
}
}
})
}, error => {
console.log("请求文件系统失败", error);
})
执行代码触发以后显示“执行失败”
{
"type": "error",
"bubbles": false,
"cancelBubble": false,
"cancelable": false,
"lengthComputable": false,
"loaded": 0,
"total": 0,
"target": {
"fileName": "/storage/emulated/0/Download/QQ/test.json",
"readyState": 2,
"result": null,
"error": {
"code": 10,
"message": "执行出错"
},
"onloadstart": null,
"onprogress": null,
"onload": null,
"onabort": null,
"onerror": "function() { [native code] }",
"onloadend": "function() { [native code] }"
}
}
【更新编译器版本前无异常!】
1 个回复
1***@qq.com (作者) - 帅
实测打包后作为App使用无异常
直接使用基座读取数据失败