uniapp 下载

2022-10-11  本文已影响0人  BJ呀呀呀
        uni.downloadFile({
                            url:fileUrl,      //文件链接
                            success: (res) => {
                                if (res.statusCode === 200) {
                                    uni.saveFile({
                                        tempFilePath: res.tempFilePath,
                                        success:(red)=> {
                                            console.log(red.savedFilePath);
                                            uni.showToast({
                                                icon: 'none',
                                                mask: true,
                                // title: '文件已保存:' + red.savedFilePath, //保存路径
                                                title: '正在打开中' ,
                                                duration: 3000,
                                            });
                                            setTimeout(() => {
                                                //打开文档查看
                                                uni.openDocument({
                                                    filePath: red.savedFilePath,
                                                    success: function(res) {
                                                        console.log('打开文档成功');
                                                    }
                                                });
                                            },3000)
                                        }
                                    });
                                }
                                
                            },
                            fail: (err) => {
                                uni.showToast({
                                    icon: 'none',
                                    mask: true,
                                    title: '失败请重新下载',
                                });
                            },
                        })
上一篇 下一篇

猜你喜欢

热点阅读