【问题标题】:React Native Expo - how to get local uri to user's media library from image pickerReact Native Expo - 如何从图像选择器获取本地 uri 到用户的媒体库
【发布时间】:2022-06-13 23:05:00
【问题描述】:

我无法找到如何从用户从媒体库中选择图像而无需重新保存/复制图像的情况下(使用 expo 包)获得像 file:///storage/emulated/0/DCIM/Camera/... 这样的本地 uri。
这为我提供了用户照片的分页结构,并包含我期望的 uri:

await MediaLibrary.getAssetsAsync({
    mediaType: [
        'photo',
    ],
});

然而,没有打开媒体库,什么是:

await ImagePicker.launchImageLibraryAsync({
    mediaTypes: ImagePickerExpo.MediaTypeOptions.Images,
    presentationStyle: 0,
});

但是,这里的 uri 类似于 file:///data/user/0/host.exp.exponent/cache/...,在我看来,它是临时缓存的 uri,而不是本地文件的永久 uri。

有没有办法从图像选择器中获取永久媒体库 uri? (基本上不必使用getAssetsAsync() 创建自己的画廊和选择器?

【问题讨论】:

    标签: react-native expo react-native-image-picker media-library


    【解决方案1】:

    这是我的代码!所以帮助你!

    if (Platform.OS === 'ios') {
    const info = await MediaLibrary.getAssetInfoAsync(item.id)
    const uri_local = info.localUri;
    item.uri = uri_local;
    console.log("test image: ", info)
    }
    else if (Platform.OS === 'android') 
    {
                    
    }
    

    【讨论】:

      猜你喜欢
      • 2021-05-14
      • 2021-06-26
      • 2020-04-23
      • 2023-01-31
      • 2022-07-20
      • 1970-01-01
      • 1970-01-01
      • 2022-11-07
      • 1970-01-01
      相关资源
      最近更新 更多