I am trying to display an image using <Image/>
from react-native
. The endpoint is built with Spring and writes the image content to output stream. The endpoint receives the image ID.
If I execute the request from Postman, in the result I can see the image.
I wondered looking for solutions and I think this one is the closest I managed to get https://stackoverflow.com/a/44058739/869793
I saw in the docs that it may work by having the response encoded with base64 but I didn't get there yet and I hope I can make it work without that.
useEffect(() => {
axios.get(
'http://localhost/images/id15',
{responseType: 'arraybuffer'}
)
.then(resp => {
const data = Buffer.from(resp.data, 'binary').toString('base64')
console.log("resp => " + data);
let imageUri = "data:image/jpeg;base64," + data;
setSource({uri: imageUri})
})
}, [])
<Image
style={styles.tinyLogo}
source={source}
/>
Outputs I get in the log by mixing in different params. Nothing displayed the image.
LOG resp => ����
LOG resp => 77+977+977+977+9
LOG resp => /f39/Q==