saveImageToPhotosAlbum(params: Object)

版本要求:
BaseKit≥3.11.0@ray-js/ray≥1.5.30
支持平台:
iOSAndroid
import { saveImageToPhotosAlbum } from '@ray-js/ray';

// Promise 调用
try {
  const res = await saveImageToPhotosAlbum({ ...params });
  console.log(res);
} catch (err) {
  console.log(err.errorMsg);
}

描述

保存图片到系统相册

参数

属性类型必填默认值说明BaseKit 最低版本
filePathstring是-图片文件路径,可以是临时文件路径也可以是永久文件路径 (本地路径)-
modifyCreationDateboolean否false是否修改视频的创建日期 默认false,不修改视频的创建日期。ture,修改视频的创建日期为当前保存时间v3.16.0
complete() => void否-接口调用结束的回调函数(调用成功、失败都会执行)-
success() => void否-接口调用成功的回调函数-
fail(params: Object) => void否-接口调用失败的回调函数-
fail 回调参数
属性类型说明
errorMsgstring错误信息
errorCodestring | number错误码
错误扩展

返回值

无

示例代码

import { downloadFile, saveImageToPhotosAlbum } from '@ray-js/ray'

// 保存图片到系统相册(需相册权限):先下载图片,再用协议路径保存
downloadFile({
  url: "https://airtake-public-data-1254153901.cos.ap-shanghai.myqcloud.com/ttttestfile/test_image.jpg",
  success: ({ tempFilePath }) => {
    saveImageToPhotosAlbum({
      filePath: tempFilePath,
      modifyCreationDate: false,
      success: () => console.log("已保存图片到相册"),
      fail: error => console.error(error),
    });
  },
  fail: error => console.error(error),
});