joltup / rn-fetch-blob

A project committed to making file access and data transfer easier, efficient for React Native developers.
MIT License
2.81k stars 773 forks source link

iOS : Error with stat with path returned by RNDocumentPicker #496

Closed omatrot closed 4 years ago

omatrot commented 4 years ago

I'm having trouble with stat on iOS:

Error: failed to stat pathfile:///private/var/mobile/Containers/Data/Application/75F278D1-A1BB-4E75-8C98-E95FC7DC86E2/tmp/com.sensoriaanalytics.CardioSensys-Inbox/Olivier__50yo_NaNcm_2019_11_24_10h_50m_26s.csvbecause it does not exist or it is not a folder

With a path returned by RBDocumentPicker on iOS.

I'm using: "react-native-document-picker": "^3.2.4", "rn-fetch-blob": "^0.10.15",

Here is the code:

DocumentPicker.pick({
          type: [DocumentPicker.types.csv]
        })
          .then(res => {
            var file;
            // if (RX.Platform.getType() === "android") {
            RNFetchBlob.fs.stat(res.uri).then(stats => {
              file = {
                uri: "file://" + stats.path,
                type: res.type,
                name: res.name
              };
              logging.logWithTimestamp(
                `Path [${file.uri}] MimeType [${file.type}] Name [${file.name}] Size [${res.size}]`
              );

I would say that the file path returned by the picker is invalid but this seems strange.

Any help appreciated.

omatrot commented 4 years ago

Solved the problem by removing "file:///private" from the beginning of The Uri returned by RNDocumentPicker.

nehaj2995 commented 4 years ago

I'm facing the same issue on both ,Android and iOS.Could you please help ?

omatrot commented 4 years ago

For Android, you have to use the following package to get the real file name :

"react-native-get-real-path": "git+https://github.com/Wraptime/react-native-get-real-path.git"

nehaj2995 commented 4 years ago

Thanks .and for iOS?

omatrot commented 4 years ago

I have no idea other than my proposed workaround above.