Javascript 在expo文档选择器上使用URI获取文件本身
我在尝试将react native(android使用expo)的文件上传到后端服务器时感觉很糟糕。 我从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
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);