已开启
fix(ohos): 等待图片压缩完成后再拉起相册保存框 #10
fix(ohos): 等待图片压缩完成后再拉起相册保存框 #10
已开启
李唐创建于 8月25日
李唐
李唐
8月25日

fix(ohos): 等待图片压缩完成后再拉起相册保存框

发现的问题是:调用 saveImageToGallery 时,如果 imageByte 比较大,那么 magePackerObj.packToFile 未完成就拉起系统保存弹窗,可能无法正常弹出确认弹窗。

likedislike
合并受阻
openharmony_ci
openharmony_ci成员
8月25日 评论:

感谢提交 Pull Requests !此PR未通过DCO校验。
校验失败可能原因:

1. 未签署“DCO协议”(开发者原创声明协议),在线签署、查看签署状态。

2. Commits 中未包含 Signed-off-by信息,参考FAQ处理。

修复上述问题后,在PR的评论框输入“check dco” ,单击”评论”,系统将再次进行DCO校验。

当前检测到如下Commits 未包含Signed-off-by信息:


Thanks for submitting a pull request. This pull request has not passed the DCO check.
Possible causes:

1. You have not signed the Developer Certificate of Origin (DCO). Sign the DCO and check DCO status.

2. The commits do not contain the Signed-off-by information. To resolve this issue, see FAQs.

After resolving the preceding issues, enter check dco in the comment box of this pull request and click Comment. The system will check DCO status again.

The following commits do not contain the Signed-off-by information:

likedislike
openharmony_ciopenharmony_ci成员
8月25日 添加了label:dco检查失败
cpf-manager
cpf-manager成员8月25日进行代码检视1
ohos/src/main/ets/components/plugin/ImageGallerySaverPlusPlugin.ets
@@ -140,0 +137,4 @@
137+ }
138+ 
139+ const title = this.sanitizeTitle(name);
140+ const filePath: string = `${this.context.filesDir}/image_${Date.now()}.png`;
cpf-manager
cpf-manager8月25日评论:

【AI-Review】【一般】【基础代码问题】【资源使用问题】临时文件未清理导致 filesDir 持续膨胀

● 问题:saveImageToGallery 用 image_${Date.now()}.png 生成唯一临时文件名(line 140),packToFile 写入数据,finally 仅 closeSync 关闭文件(line 169-171),随后 saveToPhoto 通过 fs.copyFile 复制到相册(saveToPhoto line 225-227),但复制完成后仅关闭 srcFile/desFile,未调用 fs.unlink 删除源文件。每次成功保存图片后,filesDir 下都会残留一个与原图等大的临时 png 文件。对比原代码固定使用 imageLocal.png(每次覆盖)的模式,本次变更为唯一文件名后引入了累积问题。

● 影响:一般。每次保存图片后会在 filesDir 留下与原图大小相当的临时文件(通常几 MB),频繁保存图片会导致 filesDir 持续膨胀,长期占用用户存储空间,且无清理机制。

● 建议:在 saveToPhoto 成功复制后清理临时文件,可在 line 182 调用 saveToPhoto 之后增加清理:
const result = await this.saveToPhoto(filePath, photoCreationConfigs);
try { fs.unlinkSync(filePath); } catch (_) {}
return result;
或在 saveImageToGallery 的 finally 块中追加文件删除逻辑(注意 packToFile 失败分支也要清理空文件)。

likedislike