OpenHarmony开发者论坛
标题:
接口photoAccessHelper.createAsset不能用
[打印本页]
作者:
深开鸿_王石
时间:
2024-7-29 10:54
标题:
接口photoAccessHelper.createAsset不能用
[md]### 【问题描述】
1. 使用接口photoAccessHelper.createAsset
2. 相关的代码
```
let photoType: photoAccessHelper.PhotoType = photoAccessHelper.PhotoType.IMAGE;
let extension:string = 'jpg';
let options: photoAccessHelper.CreateOptions = {
title: 'testPhoto'
}
let context = getContext(this);
let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context);
phAccessHelper.createAsset(photoType, extension, options, (err, uri) => {
if (uri !== undefined) {
console.info('createAsset uri' + uri);
console.info('createAsset successfully');
} else {
console.error(`createAsset failed, error: ${err.code}, ${err.message}`);
}
});
```
3. 运行结果、错误截图
07-29 10:50:23.721 1536-1956 C02b70/MediaLibrary com.ohos....rarydata E Common:{GrantUriPermission:1479} Can not grant uri permission, uri: file://media/Photo/6/IMG_1722221523_005/testPhoto.jpg, bundleName: com.example.myapplication, ret: 2097167
07-29 10:50:23.721 2451-2473 C02b71/MediaLibraryNapi com.examp...lication E MediaLibraryNapiUtils:{TransErrorCode:630} interface: PhotoAccessHelperCreatePhotoAsset, server errcode:-229
07-29 10:50:23.721 2451-2473 C02b70/MediaLibrary com.examp...lication E MediaLibraryNapi:{PhotoAccessCreateAssetExecute:5943} InsertExt fail, index: -229.
4. 我尝试过的解决方法和结果
申请了如下权限,
```
const permissions: Array<Permissions> = [
'ohos.permission.WRITE_IMAGEVIDEO',
'ohos.permission.READ_IMAGEVIDEO',
'ohos.permission.PROXY_AUTHORIZATION_URI',
'ohos.permission.MEDIA_LOCATION'
];
```
5. 我想要达到的结果
createAsset能创建出文件
### 【运行环境】
硬件:dayu200
ROM版本:OpenHarmony 4.1.7.605
DevEvoStudio版本:Build Version: 4.1.0.400
SDK版本:11
[/md]
欢迎光临 OpenHarmony开发者论坛 (https://forums.openharmony.cn/)
Powered by Discuz! X3.5