I'm using Angular 4 for the Front-end and Spring for the Back-end and I wanna store a user which contains an image in my database. As i know the type Blob exists in Angular 4 but it doesn't in Spring, and the type byte exists in Spring but it doesn't in Angular 4. How can I transfer my image from the Front-end to the Back-end using REST API.
This is my entity:
import java.sql.Blob;
@Entity
@Table(name = "USER_OAUTH", schema = "OAUTH")
public class UserOauth implements java.io.Serializable {
private long idUser;
private String username;
private String firstName;
private String lastName;
private String adrEmail;
private int isAdAccount;
private Date lastConnection;
private String password;
private boolean enabled;
private int attempts;
private Blob photo;
@Lob
@Column(name = "PHOTO", length = 10000000)
public Blob getPhoto() {
return photo;
}
This is my DTO :
public class UserDTO implements java.io.Serializable {
private long idUser;
private String username;
private String firstName;
private String lastName;
private String adrEmail;
private int isAdAccount;
private Date lastConnection;
private String password;
private boolean enabled;
private Blob photo;
This is my web service :(it works normally before adding the photo):
// Add a new user;
@RequestMapping(value = "/users", method = RequestMethod.POST)
public UserDTO addUser(@RequestBody final UserDTO user) throws Exception {
return modelMapper.map(userService.saveUser(modelMapper.map(user, UserOauth.class)), UserDTO.class);
}
And finally my Typescript :
export class UserData {
public idUser: number;
public username: string;
public firstName: string;
public lastName: string;
public adrEmail: string;
public isAdAccount: boolean;
public lastConnection: Date;
public password: string;
public enabled: boolean;
public photo:Blob;
}
If there is any rectifications please let me know. Thank you in advance