微信小程序ios真机调试uni.saveImageToPhotosAlbum保存报错{errMsg: "saveImageToPhotosAlbum:fail save fail:Error Domain=PHPhotosErrorDomain Code=3301 "(null)""},保存超过10mb的图片就报错这个

- 发布:2025-06-16 11:04
- 更新:2025-06-16 14:37
- 阅读:35
saveImageToPhotosAlbum:fail save fail:Error Domain=PHPhotosErrorDomain Code=3301 "(null)"

用户2837587 (作者)
** // 使用uni.downloadFile下载文件到临时目录
uni.downloadFile({
url: downloadUrl,
header: {
'Authorization': token ? Bearer ${token}
: ''
},
success: (res) => {
console.log('下载响应:', res);
if (res.statusCode === 200) {
// 检查响应头中的Content-Type
const contentType = res.header && res.header['Content-Type'];
if (contentType && contentType.includes('application/json')) {
try {
// 尝试解析JSON响应
const response = JSON.parse(res.data);
uni.showToast({
title: response.msg || '下载失败,请重试',
icon: 'none'
});
} catch (e) {
uni.showToast({
title: '下载失败,请重试',
icon: 'none'
});
}
return;
}
// 先保存到本地存储
uni.saveFile({
tempFilePath: res.tempFilePath,
success: (saveRes) => {
// 再从本地存储保存到相册
uni.saveImageToPhotosAlbum({
filePath: saveRes.savedFilePath,
success: () => {
uni.showToast({
title: '保存成功',
icon: 'success'
});
// 删除本地存储的文件
uni.removeSavedFile({
filePath: saveRes.savedFilePath,
complete: () => {
console.log('清理临时文件完成');
}
});
},
fail: (err) => {
console.error('保存到相册失败:', err);
uni.showToast({
title: '保存失败:' + (err.errMsg || '未知错误'),
icon: 'none'
});
}
});
},
fail: (err) => {
console.error('保存到本地失败:', err);
uni.showToast({
title: '保存失败:' + (err.errMsg || '未知错误'),
icon: 'none'
});
}
});
} else {
uni.showToast({
title: '下载失败:' + (res.errMsg || `状态码${res.statusCode}`),
icon: 'none'
});
}
},
fail: (err) => {
console.error('下载失败:', err);
uni.showToast({
title: '下载失败:' + (err.errMsg || '网络错误'),
icon: 'none'
});
},
complete: () => {
uni.hideLoading();
}
});
},**
用户2837587 (作者)
我是请求后端接口下载图片,然后保存的
2025-06-16 12:01