I am able to view the byte-array
image on Swagger but not on React Native. I have tried converting it to base64
and it works but I want to know how to display it in byte-array
.
- This is my backend endpoint, using spring-boot
@GetMapping(value = "/{id}", produces = { "image/jpg", "image/jpeg", "image/png" })
public ResponseEntity<Resource> getImage(@PathVariable final UUID id){
final User user = userService.findById(id).orElseThrow(() -> new ResourceNotFoundException("User Not Found."));
Optional<Image> image = imageService.findByUser(user);
if(image.isPresent()) {
byte[] bytes = Files.readAllBytes(Paths.get(image.get().getSignDocPath()));
return ResponseEntity.ok().body(new ByteArrayResource(bytes));
}
}
- And this is how I am displaying the image on React Native
<Image
source={{ uri: imageItem.url }}
style={styles.imagePreview}
/>