Hi Sverre,
in my apps (Spring Boot + Vaadin + JOOQ) I also have to store files uploaded by the user.
If I do this in the Postgresql, which is BTW not everytime a good solution, I usually split document meta data (filename, MIME type, size etc.) from document content (the byte array only).
Often, the UI shows some document meta data in the first place and storing and retrieving has to be therefore pretty easy,.
And my method for storing the maybe large content looks like this, and surprisingly the comment contains a link to this group WHY it look so :-)
/**
* @see
https://groups.google.com/g/jooq-user/c/Gwn0rce_J-Q Daher wird das hier
*/
private void storeContent(Integer id, byte[] content) {
if (this.jooq.configuration().connectionProvider() instanceof DataSourceConnectionProvider dscp) {
var dataSource = dscp.dataSource();
try (Connection conn = dataSource.getConnection();
ByteArrayInputStream is = new ByteArrayInputStream(content);
PreparedStatement ps = conn.prepareStatement("insert into document_storage (id, content) values (?, ?)")) {
ps.setInt(1, id);
ps.setBinaryStream(2, is, content.length);
ps.executeUpdate();
} catch (Exception ex) {
log.error(ex.getMessage());
}
}
}
Hope that helps
Kind regards
Dominik