将图像作为 Blob 保存到 Oracle 表时,Blob 有时会被截断。
如果图像被截断,它总是在同一位置被截断。
此外,这不是尺寸问题,这是第一个明显的答案。一张截断的图像为 126Kb,一张精细的图像为 3Mb
blob 列没有指定大小,因此根据 Oracle,它默认为 2Gb。
java代码是:
OutputStream os = null;
try {
os = image.getImage().getBinaryOutputStream();
os.write(uploadFile.getFileData());
} catch (Exception e) {
af = mapping.findForward("imageProblem");
}
最佳答案
这是因为我忘记关闭 OutputStream 造成的。在将 blob 写入表之前,它正在以令人惊讶的确定性方式被垃圾收集(我认为)。关闭流解决了问题:
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();
}
}
关于java - 保存到 Oracle 表时 Blob 被截断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18790412/