我试图上传cameraRoll张照片.问题是cameraRoll组件返回content://URI,而不是实际的文件路径.为了上传图片,我需要一个文件路径,有没有办法将content://URI转换成文件URI?谢谢

推荐答案

我接受了@Madhukar Hebbar提交的函数,并将其制作成一个React原生 node 模块.

你可以在这里找到:react-native-get-real-path

因此,为了达到你想要的效果,你可以将上述模块与react-native-fs结合使用

然后,当您想从相机卷上载所选图像时,可以执行以下操作:

RNGRP.getRealPathFromURI(this.state.selectedImageUri).then(path =>
  RNFS.readFile(path, 'base64').then(imageBase64 =>
    this.props.actions.sendImageAsBase64(imageBase64)
  )
)

React-native相关问答推荐

Reaction-原生NavBottom设计背景

如何将S的此API输出输出到平面列表中?控制台将数据及其可视记录到平面列表中,但我无法输出到平面列表中

领带麦克风在Reaction-Native-Incall-Manager中不工作

为什么当我更换屏幕时playground 音乐不会停止?

useState 函数似乎阻止了 Animated.timing 事件?

Android Studio 为构建设置 node 目录(Cause: error=2, No such file or directory)

如何在 React Native 中创建和保存 CSV 文件?

React Native 错误:Animated.event now requires a second argument for options

为了回调 URL 的目的,在 Expo 中运行的 React Native 元素的 info.plist 在哪里?

react Navigation 在标题中使用图像?

React-Native:显示加载屏幕直到加载 webview

在 React Native 中无法滚动到 ScrollView 的底部

错误:无法解析模块`buffer`

mapDispatchToProps:有什么意义吗?

在配置 react-native-maps 中获取 "supportLibVersion" 、 "playServicesVersion" 和 "androidMapsUtilsVersion" 值

React native + redux-persist:如何忽略键(黑名单)?

INSTALL_FAILED_UPDATE_INCOMPATIBLE:包签名与之前安装的版本不匹配,忽略

如何隐藏 React Native NavigationBar

zIndex 不适用于react-native元素

React Native - 导航问题undefined is not an object (this.props.navigation.navigate)