Reputation: 1852
When saving an image to an Oracle table as a blob, the blob is sometimes being truncated.
If an image gets truncated, it is always truncated in the same place.
Also, it's not a size issue, which is the first obvious answer. One image that truncates is 126Kb, and one that is fine is 3Mb
The blob column doesn't have a size specified, so according to Oracle it defaults to 2Gb.
The java code is:
OutputStream os = null;
try {
os = image.getImage().getBinaryOutputStream();
os.write(uploadFile.getFileData());
} catch (Exception e) {
af = mapping.findForward("imageProblem");
}
Upvotes: 1
Views: 361
Reputation: 1852
This was caused because I'd forgotten to close the OutputStream. It was being garbage collected (I assume), in a surprisingly deterministic fashion before it had finished writing the blob to the table. Closing the stream fixed the issue:
OutputStream os = null;
try {
os = image.getImage().getBinaryOutputStream();
os.write(uploadFile.getFileData());
} catch (Exception e) {
af = mapping.findForward("imageProblem");
} finally {
if (os != null) {
os.close();
}
}
Upvotes: 2