React Native Expo not loading local files

Viewed 128

I am developing app where local files are stored in user phone's file system. When I try to check if file exists with

var info = await FileSystem.getInfoAsync(`${AppConstants.APP_FOLDER}/main.png`);
console.log(info.exists);

It will print true. But if I try to read contents of file after checking:

var content = await FileSystem.readAsStringAsync(`${AppConstants.TILE_FOLDER}/main.png`);
console.log(content.length);

It freezes and nothing will be printed. I've tested my app on IOS in Expo Go. The filepath is like that: file:///var/mobile/Containers/Data/Application/.../app_folder/main.png

File system works properly with loading online files by url and images can be shown, while in my case they can't. How should I solve my problem? What additional data I need to provide? Thanks.

1 Answers

This isn't really an answer. But, I had something similar happen to me. You can't really trust console.log() to tell you what code is executing.

I was reading in a file and then processing the data within it. It appeared as if the FileSystem.readAsStringAsync() was hanging because my console.log() message that was directly after the FileSystem call was not being printed. But, it turned out that the problem was inside my processing code.

Once I focused on my processing code, I found the problem and corrected it. Perhaps this is what's happening in your case?

Related