use of com.ch999.haha.common.ImageRes in project haha by hahafreeasair666.
the class ImgServiceImpl method uploadImg.
@Override
public Imgs uploadImg(MultipartFile file) {
File file1 = null;
try {
if (file.getSize() >= 1024 * 100) {
// lock.lock();
log.info("图片压缩");
String str = IdWorker.get32UUID();
Thumbnails.of(file.getInputStream()).size(200, 200).toFile(str + ".jpg");
file1 = new File(str + ".jpg");
log.info("压缩完毕");
// lock.unlock();
}
} catch (Exception e) {
log.error("压缩图片异常");
}
Imgs imgs = new Imgs();
String s = HttpClientUtil.uploadFile(IMGSERVER, IMGUPLOAG_URL, file, file1);
file1.delete();
log.info("上传完毕,删除压缩图片");
ImageRes imageRes = JSON.parseObject(s, ImageRes.class);
String fid = imageRes.getFid();
String fileName = imageRes.getFileName();
Integer size = imageRes.getSize();
if (StringUtils.isBlank(fid) || size == null || size == 0) {
return null;
}
imgs.setImgName(fileName);
imgs.setImgUrl("http://" + imageRes.getFileUrl().replace("localhost", "120.79.160.214"));
imgs.setIsdel(0);
imgsService.insert(imgs);
return imgs;
}
Aggregations