Patrissol Kenfack
Patrissol Kenfack

Reputation: 863

Use URI on expo Document-picker to get the file itself

I got suck while trying to upload a file from react-native (android using expo) to a back-end server. I got from DocumentPicker.getDocumentAsync() this response

    {
      "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",
    }

My problem is now how to use the uri in order to get the file itself ? so that I could send it to the back-end server

Thanks

Upvotes: 6

Views: 2621

Answers (1)

EGPRC
EGPRC

Reputation: 95

Have you tried ExpoFileSystem.readAsStringAsync?

For example, already having the uri you talked about:

import * as ExpoFileSystem from 'expo-file-system'
...
const fileContent = await ExpoFileSystem.readAsStringAsync(uri);

And maybe you want to convert it from JSON to another format:

const content = JSON.parse(fileContent);

Upvotes: 6

Related Questions