alpha0010 / react-native-file-access

Filesystem access for React Native
MIT License
298 stars 18 forks source link

`FileSystem.stat` returns successfully but `FileSystem.readFile` fails #62

Closed ArindamRayMukherjee closed 1 year ago

ArindamRayMukherjee commented 1 year ago

react-native: 0.70.6 react-native-file-access: 2.5.2 Platform: both

Bug FileSystem.stat returns successfully

 LOG  FILE STAT : {"path":"/Users/arindamray/Library/Developer/CoreSimulator/Devices/534FEF3F-32FB-46B1-8A0E-0E1B8D5E736D/data/Containers/Data/Application/B37594E7-1C22-4B81-9F48-EAF5DBF768EE/tmp/react-native-image-crop-picker/1662E6FC-FE1C-4A44-9F98-564105871FE3.jpg","filename":"1662E6FC-FE1C-4A44-9F98-564105871FE3.jpg","size":25464,"lastModified":1675427357827.3997,"type":"file"}

But FileSystem.readFile on the same file fails with

[Error: Failed to read '/Users/arindamray/Library/Developer/CoreSimulator/Devices/534FEF3F-32FB-46B1-8A0E-0E1B8D5E736D/data/Containers/Data/Application/B37594E7-1C22-4B81-9F48-EAF5DBF768EE/tmp/react-native-image-crop-picker/1662E6FC-FE1C-4A44-9F98-564105871FE3.jpg'.]

The perms on the file are -rw-r--r-- so reading should be possible. The error message should be more descriptive on why it is failing.

To reproduce I came across this behaviour in my mobile app that tries to move a local image to an s3 location. It needs to read the contents of the file into a byte array before uploading to an s3 presigned URL. I am not sure this is a bug but I saw no other way of asking about this than filing a bug.

ArindamRayMukherjee commented 1 year ago

I was trying to load the image with no encoding supplied. When I use base64 it seems to work.