1***@qq.com
1***@qq.com
  • 发布:2024-04-17 17:55
  • 更新:2024-04-17 17:55
  • 阅读:33

#插件讨论# 【 Android-Share - 8***@qq.com 】分享文件后,文件已经存在,会自动在文件名前加上数字

分类:uni-app
关联插件: Android-Share

大佬,我目前遇到了一个问题,文件已经存在,会自动在文件名前加上数字

uniShare({
file_text: filePath,
name,
file_type
}) {
// 构造下载后的文件名
var targetFilePath = _downloads/download/${name}.${file_type};
console.log(targetFilePath,"-------构造下载后的文件名--------")
// 转换为本地文件系统URL
var targetLocalFileSystemURL = plus.io.convertLocalFileSystemURL(targetFilePath);
console.log(targetLocalFileSystemURL,"将本地URL路径转换成平台绝对路径")
// 检查文件是否存在
plus.io.resolveLocalFileSystemURL(targetLocalFileSystemURL, function(entry) {
console.log(targetLocalFileSystemURL,"直接打开")
shareModule.shareFile({
packetName: 'com.lanfff.farm', // 当前应用包名
filePath: targetLocalFileSystemURL, // 本地文件地址
wxShare: true, // 是否分享微信
}); // 分享结束后的回调方法
}, function(error) {
console.log(error,"文件不存在,开始下载")
// 文件不存在,开始下载
var dtask = plus.downloader.createDownload(filePath, {
filename: targetFilePath
}, function(d, status) {
// 下载完成
if (status == 200) {
console.log(plus.io.convertLocalFileSystemURL(d.filename),"----filePath-----")
shareModule.shareFile({
packetName: 'com.lanfff.farm', // 当前应用包名
filePath: plus.io.convertLocalFileSystemURL(d.filename), // 本地文件地址
wxShare: true, // 是否分享微信
}); // 分享结束后的回调方法
} else {
console.log("Download failed: " + status);
}
});
dtask.start();
});
}

2024-04-17 17:55 负责人:无 分享
已邀请:

要回复问题请先登录注册