react-native-blob-util icon indicating copy to clipboard operation
react-native-blob-util copied to clipboard

ReactNativeBlobUtil.fs.stat() fails with an URI path where file name contains spaces.

Open Yandamuri opened this issue 3 years ago • 2 comments

In first case, I am taking a file where file name doesn't contains spaces --> Hotel_to_office.PNG

And below is TheURIof above file

file:///private/var/mobile/Containers/Data/Application/29D722D5-D76D-4367-BB2C-AD27F2E635EE/tmp/com.growsmart.main-Inbox/Hotel_to_office.PNG

ReactNativeBlobUtil.fs.stat() is able to read above path successfully and giving the stat of the URI.

In second case, I am taking a file where file name contains spaces --> Hotel to office.PNG

And below is TheURIof above file

file:///private/var/mobile/Containers/Data/Application/29D722D5-D76D-4367-BB2C-AD27F2E635EE/tmp/com.growsmart.main-Inbox/Hotel%20to%20office.PNG ---> (This URI is slightly different where spaces are replaced with % because of spaces in the file name)

When I sent above path to ReactNativeBlobUtil.fs.stat(), I am getting following error,

Error: failed to stat path /private/var/mobile/Containers/Data/Application/29D722D5-D76D-4367-BB2C-AD27F2E635EE/tmp/com.growsmart.main-Inbox/Hotel%20to%20office.PNG because it does not exist or it is not a folder

Surprisingly this is happening only in iOS.

Below are the URIs that I tried in Android

File name with space content://com.android.externalstorage.documents/document/primary%3ADownload%2Fs%20s.pdf --> File name is s s.pdf

File name without space content://com.android.externalstorage.documents/document/primary%3ADownload%2Fss.pdf --> File name is ss.pdf

When I send above mentioned both URIs to ReactNativeBlobUtil.fs.stat(), then it gives expected results successfully.

Hence, Apparently issue is in iOS only.

May I know why ReactNativeBlobUtil.fs.stat() fails with URI path where file name contains spaces only in iOS.?

Environment Info:

    "react": "16.13.1",
    "react-native": "0.63.2",
    "react-native-blob-util": "^0.13.18",

Yandamuri avatar Feb 10 '22 10:02 Yandamuri

@Yandamuri This sounds like an issue I recently faced only on iOS when trying to send files. It turned out that for iOS I had to decode the path provided by the document picker library before using it in react-native-blob-util. This was done using the function decodeURIComponent() (no import required).

More information over here: https://github.com/rnmods/react-native-document-picker/issues/291

Give it a try – it might solve your issue too.

jaedontym avatar Feb 14 '22 01:02 jaedontym

@jaedontym Well, I certainly had fun now. I spent several hours solving a problem like yours, found your comment... and had a good laugh when I saw that it led to the solution that I proposed. :see_no_evil: Once again the problem is solved, thank you! :grin:

JerakRus avatar May 28 '24 19:05 JerakRus