积分1552 / 贡献20

提问18答案被采纳61文章39

接口photoAccessHelper.createAsset不能用

深开鸿_王石 显示全部楼层 发表于 2024-7-29 10:54:57

【问题描述】

  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

您尚未登录,无法参与评论,登录后可以:
参与开源共建问题交流
认同或收藏高质量问答
获取积分成为开源共建先驱

Copyright   ©2023  OpenHarmony开发者论坛  京ICP备2020036654号-3 |技术支持 Discuz!

返回顶部