8***@qq.com
8***@qq.com
  • 发布:2022-03-26 19:20
  • 更新:2023-05-23 09:12
  • 阅读:2575

uniapp开发的h5页面嵌入app中,在app下载附件无法下载,在浏览器中可以下载,请教一下,帮忙看下哪里有问题呢

分类:uni-app
filePreview(fileInfo){  
    const _this = this;  

    let pkPubBlob = fileInfo.pkPubBlob  
    let fileName = fileInfo.fileName  
    let xtoken = utils.cache.getItem("token");  
    let fileUrl = `${PREVIEWURL}/app/doc/downloadFile?pkPubBlob=${pkPubBlob}&fileName=${fileName}&xquant-token=${xtoken}`  
    console.log(fileUrl);  
    // if(!this.fileAllowToView(fileName).length) {  
    //  uni.showToast({  
    //      title: '该文件类型不支持手机在线查看,请切换至电脑端',  
    //      icon: "none",  
    //      duration: 4000  
    //  });  
    //  return false;  
    // }  
    if(_this.isIMG(fileName).length){  
        uni.previewImage({  
            urls: [fileUrl],  
        });  
    } else {  
        // #ifdef APP-PLUS  
        uni.showToast({  
            title: "APP-附件下载",  
            icon: "none",  
            duration: 3000  
        });  
        _this.openRemoteFile(fileUrl)  
        // #endif  
        // #ifndef APP-PLUS  
        uni.showToast({  
            title: "H5-附件下载",  
            icon: "none",  
            duration: 3000  
        });  
        _this.openFile(encodeURI(fileUrl))  
        // #endif  
    }  
},  
//打开本地文件  
openRemoteFile(url) {  
    uni.showLoading({  
        title: '正在打开文件...',  
        mask: true  
    });  
    var dtask = plus.downloader.createDownload(encodeURI(url), {  
        method: "GET"  
    }, function(d, status) {  
        if (status == 200) {  
            plus.runtime.openFile(d.filename, {}, function(e) {  
                uni.hideLoading();  
                console.log("无法打开此文件:" + e.emssage, "查看附件");  
            });  
            uni.hideLoading();  
        } else {  
            uni.hideLoading();  
            console.log("文件打开失败: " + status, "查看附件");  
        }  
    });  
    dtask.start();  
},  
openFile(url) {  
    console.log("H5");  
    var link = document.createElement('a');  
    link.href = url;  
    link.target = '_blank';  
    link.click();  
    link.remove();  
},
2022-03-26 19:20 负责人:无 分享
已邀请:
FullStack

FullStack - 【插件开发】【专治疑难杂症】【ios上架、马甲包、白包、过审、已成功上架过几百个】【多款插件已上架:https://ext.dcloud.net.cn/publisher?id=22130】【非诚勿扰】QQ:543610866

app要用专门下载api

7***@qq.com

7***@qq.com

这个问题有没有一个明确的解决方案

l***@126.com

l***@126.com

一样不知道怎么解决

1***@163.com

1***@163.com

你这个下载文件的逻辑就是创建一个a标签,然后利用a标签的_blank达到下载的效果。这样在h5中是可以的,但是在app或者小程序中是不可以的。
分享一个小程序内嵌h5的处理思路。

假设h5页面为A,当在h5中点击文件下载时,这时候要跳到小程序的一个下载页面B,
在B中处理下载文件的逻辑,然后可以预览,当需要预览结束需要返回时,再返回h5页面。

piaoyi_UI

piaoyi_UI - 【插件开发】【专治疑难杂症】【多款插件已上架:https://ext.dcloud.net.cn/publisher?id=193663(微信搜索飘逸科技UI小程序直接体验)】【骗子请绕道】问题咨询请加QQ群:120594820,代表作灵感实用工具小程序

看一下uni.downloadFile

要回复问题请先登录注册