小程序视频下载安卓端,pc端,体验版都没问题。ios下载就报错,分享解决办法

代码

复制代码
videos.forEach((url, index) => {
						var filepath = wx.env.USER_DATA_PATH + '/' + new Date().valueOf() + '.mp4'
						uni.downloadFile({
							url: url, //视频的地址
							filePath: filepath,
							header: {
								'content-type': 'application/json'
							},
							success: function(res) {
								console.log(res, '111')
								uni.saveVideoToPhotosAlbum({
									// filePath: modifiedPath,
									filePath: res.filePath,
									success: (ers) => {
										uni.hideLoading();
										setTimeout(() => {
											uni.showToast({
												title: '保存成功'
											});
										}, 600)
									},
									fail: (err) => {
										console.log(err, '444')
										uni.showToast({
											title: '保存失败',
											icon: 'error'
										});
									}
								});
                                 },
							fail: (err) => {
								console.log(err, '1012')
							},
						})
					})

苹果端报错:

后来查了大量资料,找到

一试就成了,视频格式转换可以下载《格式工厂》

,在记录一个安卓苹果都能用的图片下载

复制代码
uni.showLoading({
					title: '素材下载中'
				});
				var image = images
				// 图片下载
				let filename = new Date().getTime() + ".jpg";
				if (images.length > 0) {
					image.forEach((url, index) => {
						let uniqueFilename = new Date().getTime() + "_" + index + ".jpg";
						let filePath = wx.env.USER_DATA_PATH + "/" + uniqueFilename; // 每次生成唯一的文件路径
						uni.downloadFile({
							url: url, //图片的地址
							filePath: filePath,
							success: function(res) {
								uni.saveImageToPhotosAlbum({
									filePath: res.filePath,
									success: (red) => {
										uni.hideLoading();
										setTimeout(() => {
											uni.showToast({
												title: '保存成功'
											});
										}, 600)
									},
									fail: (err) => {
										console.log(err, '000')
										uni.hideLoading();
										uni.showToast({
											title: '保存失败',
											icon: 'error'
										});
									}
								});
							},
							fail: (err) => {
								console.log(err)
							},
						})
					})
				}
相关推荐
JJay.2 分钟前
Kotlin 高阶函数学习指南
android·开发语言·kotlin
jinanwuhuaguo6 分钟前
截止到4月8日,OpenClaw 2026年4月更新深度解读剖析:从“能力回归”到“信任内建”的范式跃迁
android·开发语言·人工智能·深度学习·kotlin
JJay.1 小时前
Android Kotlin 协程使用指南
android·开发语言·kotlin
BLUcoding1 小时前
Android 布局介绍
android
summerkissyou19872 小时前
android-蓝牙-状态和协议值总结及监听例子
android·蓝牙
徒 花2 小时前
数据库知识复习05
android·数据库
mon_star°4 小时前
消防安全培训小程序项目亮点与功能清单
小程序
提子拌饭1334 小时前
番茄时间管理:鸿蒙Flutter 实现的高效时间管理工具
android·flutter·华为·架构·开源·harmonyos·鸿蒙
4311媒体网4 小时前
帝国CMS二次开发实战:精准实现“最新资讯”标识与高亮判断
android
编程迪4 小时前
基于Java和Vue开发的在线问诊系统医疗咨询小程序APP
小程序