Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/445.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

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
Javascript 在expo文档选择器上使用URI获取文件本身_Javascript_React Native_Expo - Fatal编程技术网

Javascript 在expo文档选择器上使用URI获取文件本身

Javascript 在expo文档选择器上使用URI获取文件本身,javascript,react-native,expo,Javascript,React Native,Expo,我在尝试将react native(android使用expo)的文件上传到后端服务器时感觉很糟糕。 我从DocumentPicker.getdocumentsync()得到了这个响应 { "name": "QuitusInscription_30769_59.pdf", "size": 41438, "type": "success", "uri": "file:///data/user/0/host.exp.exponent/cache

我在尝试将react native(android使用expo)的文件上传到后端服务器时感觉很糟糕。 我从
DocumentPicker.getdocumentsync()
得到了这个响应

    {
      "name": "QuitusInscription_30769_59.pdf",
      "size": 41438,
      "type": "success",
      "uri": "file:///data/user/0/host.exp.exponent/cache/ExperienceData/%2540anonymous%252Fcsdl_frontend-46ddf63e-90ab-44b3-a4c7-6ad7aad5cccc/DocumentPicker/a40a6599-4900-439a-9e9b-57fa555a80c9.pdf",
    }
我现在的问题是如何使用uri来获取文件本身?这样我就可以把它发送到后端服务器


谢谢

您尝试过ExpoFileSystem.readAsStringAsync吗

例如,已经有了您提到的uri:

import * as ExpoFileSystem from 'expo-file-system'
...
const fileContent = await ExpoFileSystem.readAsStringAsync(uri);
也许您想将其从JSON转换为另一种格式:

const content = JSON.parse(fileContent);