如果是标签中显示
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
public void attachPic() throws IOException {
RequestParams requestParams = createRequestParams();
String filePath = requestParams.getQueryValue("filePath");
String fileName = requestParams.getQueryValue("fileName");
logger.error("图片路径:"+filePath);
if(fpath.contains("GRD-RESOURCE")){
// 可用于读取封装过文件服务器上的图片 CFSClient 为 封装后的sdk 不同项目提供者不同
CFSClient client = new CFSClient(gwUrl);
try{
byte[] bytes = client.getObject(fpath+"/"+fileName);
if(bytes != null){
response.setContentType("image/jpeg");
os = response.getOutputStream();
os.write(bytes);
}
}catch(Exception e){
os.println(e.getMessage());
} finally {
if(os != null){
os.close();
}
}
}else{
// 读取没有封装过的图片服务器
File folder = new File(fpath);
if (!folder.exists()) {
logger.info(FILE_NOT_EXIST + fpath);
throw new NovatarRuntimeException(FILE_NOT_EXIST + fpath);
}
if (folder.isDirectory()) {
File[] fs = folder.listFiles();
if (null == fs || 0 == fs.length) {
logger.info(FILE_NOT_EXIST + fpath);
throw new NovatarRuntimeException(FILE_NOT_EXIST + fpath);
}
File showFile = fs[0];
IOUtils.write(FileUtils.readFileToByteArray(showFile), os);
}
}
}
调用
<img src="/base/register/attachPic.pvt?filePath=6a5950142198ab51b8cbe16b0268d1ba04efa349899d85ea30e93181fb3b02aa1bc8a2f4341aaf12b986ecca197028550fc4e03b0f7593026dbbdcab0826ea14d0eefbad1b5d49f32bbc76fae5370a61444198765482100f0ff834a160ae25deceabc342f9dda9c3f67fe1aa395fe855&fileName=jsz.jpg" width="20" height="16">