

English
保存图片到系统相册
name | type | required | default | description |
---|---|---|---|---|
options | SaveImageToPhotosAlbumOptions | YES | - | - |
name | type | optinal | default | description |
---|---|---|---|---|
filePath | string | YES | - | 图片文件路径,可以是临时文件路径也可以是永久文件路径,不支持网络图片路径 |
success | (callback: SaveImageToPhotosAlbumSuccess) => void | NO | - | 接口调用成功的回调函数 |
fail | (callback: IMediaError) => void | NO | - | 接口调用失败的回调函数 |
complete | (callback: any) => void | NO | - | 接口调用结束的回调函数(调用成功、失败都会执行) |
name | type | optinal | default | description |
---|---|---|---|---|
path | string | YES | - | 保存到相册的图片路径 |
name | type | optinal | default | description |
---|---|---|---|---|
errCode | 1101001 | 1101002 | 1101003 | 1101004 | 1101005 | 1101006 | 1101007 | 1101008 | 1101009 | 1101010 | YES | - | 错误码 - 1101001 用户取消 - 1101002 urls至少包含一张图片地址 - 1101003 文件不存在 - 1101004 图片加载失败 - 1101005 未获取权限 - 1101006 图片或视频保存失败 - 1101007 图片裁剪失败 - 1101008 拍照或录像失败 - 1101009 图片压缩失败 - 1101010 其他错误 |
errSubject | string | YES | - | 统一错误主题(模块)名称 |
data | any | NO | - | 错误信息中包含的数据 |
errMsg | string | YES | - | - |
Android version | Android uni-app | Android uni-app-x | iOS version | iOS uni-app | iOS uni-app-x |
---|---|---|---|---|---|
4.4 | √ | 3.9+ | - | - | - |
<template>
<!-- #ifdef APP -->
<scroll-view style="flex:1">
<!-- #endif -->
<image src="/static/uni.png" style="margin: 30rpx 200rpx;height:350rpx;width: 350rpx;"></image>
<button style="margin: 30rpx;" @click="saveImage">将图片保存到手机相册</button>
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template>
<script>
export default {
data() {
return {
}
},
methods: {
saveImage() {
uni.saveImageToPhotosAlbum({
filePath: "/static/uni.png",
success() {
uni.showToast({
position: "center",
icon: "none",
title: "图片保存成功,请到手机相册查看"
})
},
fail(e) {
uni.showModal({
content: "保存相册失败,errCode:" + e.errCode + ",errMsg:" + e.errMsg + ",errSubject:" + e.errSubject,
showCancel: false
});
}
})
}
}
}
</script>
<style>
</style>
name | type | optinal | default | description |
---|---|---|---|---|
errMsg | string | YES | - | 错误信息 |