HarmonyOS photoAccessHelper.getAssets报错:errCode:14000014 errMsg:member not exist

​​通过photoViewPicker取得照片的uri后,再使用photoAccessHelper.getAssets,出现报错:

errCode:14000014 errMsg:member not exist

工程机版本:ALT-AL10 3.0.0.22(SP35DEVC00E22R6P1log)

DevEco Studio版本:5.0.3.200

SDK版本:5.0.0.22​

async handle():void{ 
  const count =4; 
 
  const photoSelectOptions = new photoAccessHelper.PhotoSelectOptions(); 
  photoSelectOptions.MIMEType = photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE; // 过滤选择媒体文件类型为IMAGE 
  photoSelectOptions.maxSelectNumber = count; // 选择媒体文件的最大数目 
 
  const photoViewPicker = new photoAccessHelper.PhotoViewPicker(); 
  try { 
  const photoSelectResult: photoAccessHelper.PhotoSelectResult = await photoViewPicker.select(photoSelectOptions); 
  const uris = photoSelectResult.photoUris; 
  console.info('photoViewPicker.select to file succeed and uris are:' + uris); 
  const tempImgs: Array<TempImage> = []; 
  for (let i = 0 ; i < uris.length ; i++) { 
  const tempImg = await getImageInfo(uris[i], getContext(this)); 
  tempImgs.push(tempImg); 
} 
} catch (err) { 
  return this.onFailure(-1, `selectImages error occurs. ${err}`); 
} 
} 
 
async function getImageInfo(uri: string, context: Context): Promise<TempImage> { 
  let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 
  let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 
  predicates.equalTo(photoAccessHelper.PhotoKeys.URI, uri.toString()); 
  let fetchOptions: photoAccessHelper.FetchOptions = { 
    fetchColumns: [], 
    predicates: predicates 
  }; 
 
  let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 
  let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 
  const PhotoKeys = photoAccessHelper.PhotoKeys; 
  const pixelMap = await photoAsset.getThumbnail({ width: 120, height: 120 }) 
  const base64 = await converToBase64(pixelMap); 
  const result: TempImage = { 
    file_size: photoAsset.get(PhotoKeys.SIZE) as number, 
    file_type:  convertToFileType(photoAsset.photoType) as number, 
    image_height: photoAsset.get(PhotoKeys.HEIGHT) as number, 
    image_width: photoAsset.get(PhotoKeys.WIDTH) as number, 
    original_height: photoAsset.get(PhotoKeys.HEIGHT) as number, 
    original_width: photoAsset.get(PhotoKeys.WIDTH) as number, 
    path: uri, // "file:///private/var/mobile/Containers/Data/Application/D64C9CD3-3E33-412C-BFCC-1BAEFF52887B/tmp/0DF557E6-ED48-4696-BB94-8C4104A67870" 
    path_uri: uri, // "/tmp/0DF557E6-ED48-4696-BB94-8C4104A67870" 
    thumb: base64 
  } 
 
  console.info('base64: ' + base64); 
  fetchResult.close(); 
  return result; 
}
HarmonyOS
2024-11-13 09:16:36
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
zbw_apple

​请将IDE升级到canary3版本,5.0.3.300重新编译成员参数名称,在get时,除了uri、photoType和displayName三个属性之外,其他的属性都需要在fetchColumns中填入需要get的PhotoKeys,例如:get title属性fetchColumns: [‘title’]。

https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-photoaccesshelper-V5#ZH-CN_TOPIC_0000001893368817__get

分享
微博
QQ
微信
回复
2024-11-13 15:50:53
相关问题
HarmonyOS调用PhotoAccessHelper.getAssets问题
462浏览 • 1回复 待解决
The <canvas> component does not exist.
8474浏览 • 3回复 待解决
提问
该提问已有0人参与 ,帮助了0人