ctx.draw(false, () => {
// #ifdef APP-HARMONY
console.log('HARMONY 平台 - Canvas 绘制完成,开始转换为临时文件')
// #endif
uni.canvasToTempFilePath({
canvasId,
width: imageSize,
height: imageSize,
destWidth: imageSize,
destHeight: imageSize,
success: (res) => {
// #ifdef APP-HARMONY
console.log('HARMONY 平台 - 临时文件生成成功,路径:', res)
console.log(typeof res)
const tempFilePath = res.tempFilePath
// #endif
uni.saveImageToPhotosAlbum({
filePath: tempFilePath,
success: (res) => {
// #ifdef APP-HARMONY
console.log(`HARMONY 平台 - 保存到相册成功${res}`)
// #endif
uni.showToast({ title: '已保存到相册', icon: 'success' })
},
fail: (err) => {
// #ifdef APP-HARMONY
console.error('HARMONY 平台 - 保存到相册失败:', JSON.stringify(err))
// #endif
},
})
},
fail: (err) => {
// #ifdef APP-HARMONY
console.error('HARMONY 平台 - 图片转换失败:', JSON.stringify(err))
// #endif
uni.showToast({ title: '图片转换失败', icon: 'none' })
},
})
}) - 发布:2025-11-18 17:13
- 更新:2025-11-20 13:13
- 阅读:111
产品分类: uniapp/App
PC开发环境操作系统: Mac
PC开发环境操作系统版本号: 15.5
HBuilderX类型: Alpha
HBuilderX版本号: 4.86
手机系统: HarmonyOS NEXT
手机系统版本号: HarmonyOS 5.1.0
手机厂商: 华为
手机机型: MatePad 11.5S
页面类型: vue
vue版本: vue3
打包方式: 离线
项目创建方式: HBuilderX
示例代码:
操作步骤:
直接调用saveImageToPhotosAlbum 保存临时路径的图片
直接调用saveImageToPhotosAlbum 保存临时路径的图片
预期结果:
直接保存到相册
直接保存到相册
实际结果:
保存到相册失败: {"errMsg":"saveImageToPhotosAlbum:fail Invalid input parameter."}
保存到相册失败: {"errMsg":"saveImageToPhotosAlbum:fail Invalid input parameter."}
bug描述:
鸿蒙 next 系统使用saveImageToPhotosAlbum 报错,{"errMsg":"saveImageToPhotosAlbum:fail Invalid input parameter."}
DCloud_UNI_OttoJi - 日常回复 uni-app/x 问题,如果艾特我没看到,请主动私信
因为你不提供可直接运行的代码,提到网络下载之后进行保存是报错的。我使用 HBuilderX 4.86alpha 运行到鸿蒙表现正常
<template>
<view>
<button @click="save1">saveImage</button>
</view>
</template>
<script setup>
const save1 = () => {
console.log('save1 tap!');
uni.downloadFile({
url: 'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/logo.png',
success(res) {
console.log('download', res.tempFilePath);
const file = res.tempFilePath
uni.saveImageToPhotosAlbum({
filePath: file,
success: function() {
console.log('save success');
}
});
}
})
}
</script>
点击按钮,会正常出现保存图片的弹窗提示。你可根据我的代码进行修改,说明你的问题
-
7***@qq.com (作者)
使用你提供代码测试还是报错,我添加调用失败的方法,出现了以下报错信息
11:17:21.517 ERR_FILE_NOT_FOUND
11:17:22.654 save1 tap! at pages/test/test.vue:17
11:17:22.781 download /data/storage/el2/base/cache/UNI0xxxx6/uni-download/logo(8).png at pages/test/test.vue:21
11:17:22.802 photoAccessHelper getPhotoAccessHelper inner add createDeleteRequest and showAssetsCreationDialog
11:17:22.802 photoAccessHelper bundleName is com.xxxxx.avatar.
11:17:22.804 photoAccessHelper appId is com.xxxxx.avatar_BJ+xxhNida+21vvd0zp5H6fNTFC2U9NrynanPYirX46Z4v/Enpz6+lUvlcJIdyRA4FVGULKTl4ceesjpumCxtf8=.
11:17:22.804 photoAccessHelper labelId is com.xxxxx.avatar_BJ+xxhNida+21vvd0zp5H6fNTFC2U9NrynanPYirX46Z4v/Enpz6+lUvlcJIdyRA4FVGULKTl4ceesjpumCxtf8=.
11:17:22.808 photoAccessHelper modeleName is .
11:17:22.810 save fail {errMsg: "saveImageToPhotosAlbum:fail Invalid input parameter."} at pages/test/test.vue:302025-11-25 11:20
-
-
-
-
7***@qq.com (作者)
直接调用方法uni.saveImageToPhotosAlbum可以测试
2025-11-20 11:05
7***@qq.com (作者)
无论是从网络下还是临时文件保存都报以上错误
2025-11-20 11:06