how i can get te byte[] from file upload using the primeNg fileupload i need to save it in a model to persist in my database java backend: in the backend i have this
Class User{ List<UserDocument> } class UserDocument{ @Column(name = "name", length = 100, nullable = false) private String name; @Column(name = "description", length = 255) private String description; @Column(name = "type", length = 100, nullable = false) private String type; @Lob @Basic(fetch = FetchType.LAZY) @Column(name = "content", nullable = false) private byte[] content; @ManyToOne(optional = false) @JoinColumn(name = "USER_ID") private User user; }
so in angular 6 i also have the user and userdocuments model, i dont need to post the upload files before the user because the user dont exist at this time...
i need to create the user with their usedocuments at same time.
so in angular i have a form with username filds, etc, and the primeng fileupload, what i do is when you upload at file, i get the event and create a new userDocument model from event.files
onUpload(event) {
let fileReader = new FileReader();
for (let file of event.files) {
const userDocument: UserDocument = new UserDocument();
userDocument.name = file.name;
userDocument.description = file.description;
userDocument.type = file.type;
userDocument.content = file; /// i need to set here the file byte[]
}
}
in angular userDocument.content is a any[]
im trying, how i can get the byte[] from file?
thanks