There is a way to convert inputStream to a String, and encode it to base64, right? In my function, I get InputStream param, and need to insert it into the BLOB field in my Oracl
As I mentioned, you shouldn't use String
for binary data. The base64-encoded data can be stored as a String though. But since your database column is a blob, I would continue to work with a byte[]
.
Use IOUtils to get a byte[]
from the InputStream
:
byte[] bytes = IOUtils.toByteArray(yourInputStream);
byte[] encoded = java.util.Base64.getEncoder().encode(bytes);
Then write it to the database. Writing a blob using jdbc and a PreparedStatement looks like this:
yourPreparedStatement.setBytes(nIndex, encoded);