小程序视频下载安卓端,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)
							},
						})
					})
				}
相关推荐
Jerry11 小时前
Navigation 最佳实践
android
Just_Paranoid12 小时前
【Android UI】Android 颜色的表示和获取使用指南
android·ui·theme·color·attr·colorstatelist
louisgeek12 小时前
Android Charles Proxy 抓包
android
Exploring14 小时前
从零搭建使用 Open-AutoGML 搜索附近的美食
android·人工智能
ask_baidu14 小时前
Doris笔记
android·笔记
lc99910214 小时前
简洁高效的相机预览
android·linux
hqk15 小时前
鸿蒙ArkUI:状态管理、应用结构、路由全解析
android·前端·harmonyos
消失的旧时光-194315 小时前
从 C 链表到 Android Looper:MessageQueue 的底层原理一条线讲透
android·数据结构·链表
方白羽15 小时前
Android 中Flags从源码到实践
android·app·客户端
深蓝电商API15 小时前
从数据采集到商业变现:网络爬虫技术的实战与边界
android·爬虫