iOS: It's not working with local URI returned by RNFS.LibraryDirectoryPath
iamamanbirdi opened this issue · 3 comments
It's not working with local URI, such as that returned by RNFS.LibraryDirectoryPath in the react-native-fs library.
In my case the URI value is /Users/aman.birdi/Library/Developer/CoreSimulator/Devices/674B2D17-A812-42C9-8E54-1D01D353967C/data/Containers/Data/Application/05897FAC-C6A7-4FD4-A118-E4199C98A8B4/Library/Caches/Books/ae038166-d3a3-49f9-920d-8fd35ec21ba2_small_cover.jpg
.
I tried to pass it with and without require
but no luck.
For now you can use readFile
from react-native-fs and use base64 encoding.
https://github.com/itinance/react-native-fs#readfilefilepath-string-encoding-string-promisestring
Concatenate the image file mime type to the base64 string if its missing (the part in bold):
"data:image/jpeg;base64,/9j/4Ri..."
You can pass this string.
const imageBase64 = "data:image/jpeg;base64,/9j/4Ri..."
const colors = await ImageColors.getColors(imageBase64 )
For now I'll keep a lookout for more issues like this. If it seems very common then I'll consider adding support for this usecase directly into the library (pull requests welcome meanwhile).
Thanks for replying, I'll try the base64 approach and post the results.
Working fine after getting base64 from localURI.