Hello I have spring boot application in my table I store image as byte [] arr. Via the get request I send the my result to the ionic app to the display. However in it does not display image.
Here is the code, `
Java Spring Boot (Model)
@Column(name = "image")
public byte []getImage() {
return image;
}
public void setImage(byte [] image) {
this.image = image;
}
Java Spring Boot Controller
@GetMapping("/drivers/{id}")
public ResponseEntity<Drivers> getEmployeeById(@PathVariable(value = "id") Long driverId)
throws Exception {
Drivers employee = driverRepository.findById(driverId)
.orElseThrow(() -> new Exception("Employee not found for this id :: " + driverId));
return ResponseEntity.ok().body(employee);
}
Angular/Ionic
etchAlarms(){
return this.http.get<any>('http://localhost:8080/api/getAllDrivers')
.subscribe(transformedData =>{
this.alarmsChanged.next(transformedData);
});
}
HTML
<img src="data:image/png;base64,{{alarms.image}}"/>
I read almost all the question related this, but unfortunately I couldnt solve the problem.
Here is some of the related questions I have checked;
How to display base64 image on iPhone in Ionic 4
How to display image in ionic 4 using angular js
Base64 encoded image is not displaying in ionic framework apps
Ionic / AngularJS base64 image won't display
Thank You very much. Any help is appreciated
EDIT
Here is error from chrome console
unsafe:data:image/png;base64,:1 GET unsafe:data:image/png;base64, net::ERR_UNKNOWN_URL_SCHEME
encodedfile = new String(Base64.encodeBase64(bytes), "UTF-8");encodedfile = new String(Base64.encodeBase64(bytes), "UTF-8");are available, you should be able to continue storing your image in the database as bytes. You just need to make the conversion from the bytes to Base64 by the time your reach the view layer for image rendering. This could happen in the getter method of the service that accesses the database (e.g.getImageBytesAsBase64()) or in the controller that sits between the service and the view, or in a helper class that multiple controllers use.