雷霆嘎巴
雷霆嘎巴
  • 发布:2020-12-25 15:18
  • 更新:2020-12-26 11:55
  • 阅读:1418

App 下载视频到本地相册

分类:uni-app
const downloadTask = uni.downloadFile({  
                        url: url,  // 视频的下载地址  
                        success: (data) => {  
                            if (data.statusCode === 200) {  
                                 uni.saveImageToPhotosAlbum({ // 需要保存到相册 如果是下载文件 用uni.saveFile()  
                                      filePath: data.tempFilePath, // 视频的本地临时地址  
                                      success: function (res) {  
                                          console.log('下载成功')  
                                        uni.showToast({  
                                            title: '下载完成,请到相册查看',  
                                            position: 'center',  
                                            icon: 'none',  
                                            duration: 2000  
                                        });  
                                      },  
                                      fail: () => {  
                                        uni.showToast({  
                                            title: '下载视频失败请重试',  
                                            position: 'center',  
                                            icon: 'none',  
                                            duration: 2000  
                                        });  
                                      }  
                                    });  
                            }  
                        },  
                        fail: (err)=>{  
                            this.downText = '下载视频'  
                            uni.hideLoading()  
                            uni.showToast({  
                                title: err,  
                                position: 'center',  
                                icon: 'none',  
                                duration: 2000  
                            });  
                        },  
                        complete: ()=>{  
                            this.downText ='下载视频'  
                        }  
                    });  

                    downloadTask.onProgressUpdate((res) => { // 下载进度  
                        this.downText = `已下载${res.progress}%`  
                        if(res.progress == 100){  
                            this.downText = '下载视频'  

                        }  
                    });
0 关注 分享

要回复文章请先登录注册

[已删除]

[已删除]

承接H5、小程序、APP等外包:
1. 经验丰富,做过多种类型项目,有案例可看;
2. 整个项目外包可以找我(小团队接单,面向客户、产品);
3. 只需要前端部分也可以找我(个人接单,面向服务端合作伙伴);
4. wechat、tel(13070273424);
2020-12-26 11:55
MonikaChen

MonikaChen

如果将一个txt文件下载并保存到默认的Download文件夹?
2020-12-25 23:40