使用 plus.io.chooseFile 上传文件 本地离线打包后,无法选择非媒体文件,选择文件的回调都不执行;云打包没有权限开启弹窗?有什么解决方案
handleAnrdroid() {
const permissionID = 'android.permission.READ_EXTERNAL_STORAGE';
permission.requestAndroidPermission(permissionID).then((res) => {
if (res === 1) {
_this.chooseSystemFile();
} else {
uni.showModal({
title: '无法访问存储',
content: '您已经关闭存储权限,请前往权限管理中允许当前应用访问存储',
success: (res) => {
if (res.confirm) {
// 跳转到手机的权限管理
permission.gotoAppPermissionSetting();
}
},
});
}
});
},
chooseSystemFile() {
const _this = this;
plus.io.chooseFile(
{
title: '选择文件',
// filetypes: ['kmz', 'kml'], // 文件类型过滤(部分系统可能不生效)
multiple: false, // 是否多选
},
(e) => {
try {
console.log('e', e);
const fileUri = e.files[0]; // 获取首个文件路径
uni.getFileInfo({
filePath: fileUri,
success: (res) => {
console.log('res', res);
const fileSize = res.size / 1024 / 1024;
if (fileSize > _this.fileSizeLimit) {
return uni.showToast({
title: 文件不能超过${_this.fileSizeLimit}M
,
icon: 'none',
duration: 3000,
});
}
let uploadPath = fileUri;
// Android 特殊处理:转换 content:// URI
if (plus.os.name.toLowerCase() === 'android' && fileUri.startsWith('content://')) {
uploadPath = _this.resolveAndroidContentUri(fileUri);
}
const name = uploadPath.split('/').pop();
_this.files = [{ name: name, path: uploadPath }];
},
});
} catch (error) {
console.log('error', error);
}
},
(err) => {
console.log('选择文件失败:', err);
}
);
},
0 个回复