关于导入图片的使用权限和问题
==============

**问题描述**

需要导入图片并获取图片地址，然后传递到底层C++代码。经过测试发现，导入后读取图片时失败。

**问题定位**

当前手机不支持在C++层直接打开公共路径。仅支持在TS侧打开后，将文件描述符（fd）传递到C侧，然后使用dopen进行打开。

**参考代码**

将公共路径下的文件保存至沙箱路径，并将文件描述符（fd）传入C侧。C侧通过fd操作文件。

import { BusinessError } from '@kit.BasicServicesKit';
import { fileIo } from '@kit.CoreFileKit';
import { common } from '@kit.AbilityKit';
import { photoAccessHelper } from '@kit.MediaLibraryKit';

let context = AppStorage.get("context") as UIContext;
let filesDir = context.getHostContext()?.filesDir;
async function savePictureToContext() {
  const photoSelectOptions = new photoAccessHelper.PhotoSelectOptions();
  photoSelectOptions.MIMEType =
    photoAccessHelper.PhotoViewMIMETypes.IMAGE\_TYPE; _// Filter and select media file type as IMAGE_
  photoSelectOptions.maxSelectNumber = 5; _// Select the maximum number of media files_
  let uris: Array<string> = \[\];
  const photoViewPicker = new photoAccessHelper.PhotoViewPicker();
  let photoSelectResult = await photoViewPicker.select(photoSelectOptions);
  uris = photoSelectResult.photoUris;
  let uri: string = uris\[0\];
  let file = fileIo.openSync(uri, fileIo.OpenMode.READ\_ONLY);
  console.info('file fd: ' + file.fd);
  let fd = file.fd;
  fileIo.copyFileSync(fd, filesDir + '/test2.jpg')
  let file2 = fileIo.openSync(filesDir + '/test2.jpg', fileIo.OpenMode.READ\_ONLY);
  let file3 = fileIo.openSync(filesDir + '/test3.jpg', fileIo.OpenMode.READ\_WRITE | fileIo.OpenMode.CREATE);
 _ // After passing fd in, the C end can call it_
  _// ReadFile(file2.fd,file3.fd)_
}