Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native react native中实际路径的uri_React Native_Path_Uri - Fatal编程技术网

React native react native中实际路径的uri

React native react native中实际路径的uri,react-native,path,uri,React Native,Path,Uri,我使用react native document picker在Android和IOS中选择图像和视频。 问题是它返回一个uri,我需要实际路径 我尝试使用带有函数stat的react-native fetch blob和带有函数stat的react-native fs。两者都不适用于URI。但如果我使用react native fs readFile,它可以与URI一起工作 react native get real path仅适用于Android,因此不是一个选项 编辑: 有人建议我使用rn

我使用react native document picker在Android和IOS中选择图像和视频。 问题是它返回一个uri,我需要实际路径

我尝试使用带有函数stat的react-native fetch blob和带有函数stat的react-native fs。两者都不适用于URI。但如果我使用react native fs readFile,它可以与URI一起工作

react native get real path仅适用于Android,因此不是一个选项

编辑: 有人建议我使用rn fetch blob,但我在安装时遇到问题:


我尝试使用react native get real path来区分Android和IOS,但它也有问题。

最后,我使用了ios的react-native document picker和android的react-native file picker

最后,我使用了ios的react-native document picker和android的react-native file picker

请正确格式化此代码,使其可读性更好。:)请正确设置此代码的格式,使其可读性更好。:)
File file = new File(getURIPath(uriValue));

/**
 * URI Value
 * @return File Path.
 */
String getURIPath(Uri uriValue) 
    {
        String[] mediaStoreProjection = { MediaStore.Images.Media.DATA };
        Cursor cursor = getContentResolver().query(uriValue, mediaStoreProjection, null, null, null);
        if (cursor != null){ 
        int colIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        cursor.moveToFirst();
        String colIndexString=cursor.getString(colIndex);
        cursor.close();
        return colIndexString;
        }
        return null;
    }