代码
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)},})})}