👽 halo_attachment表新增attach_size和attach_wh,上传附件会保存附件大小和尺寸

pull/18/head
ruibaby 2018-06-23 23:27:02 +08:00
parent 3e262390ea
commit c6a4b2de20
4 changed files with 31 additions and 11 deletions

View File

@ -60,4 +60,14 @@ public class Attachment implements Serializable {
*
*/
private Date attachCreated;
/**
*
*/
private String attachSize;
/**
*
*/
private String attachWh;
}

View File

@ -193,6 +193,22 @@ public class HaloUtils {
return cal.getTime();
}
/**
*
*
* @param file file
* @return String
*/
public static String getImageWh(File file) {
try {
BufferedImage image = ImageIO.read(new FileInputStream(file));
return image.getWidth() + "x" + image.getHeight();
} catch (Exception e) {
e.printStackTrace();
return "";
}
}
/**
*
*

View File

@ -166,6 +166,8 @@ public class AttachmentController {
attachment.setAttachType(file.getContentType());
attachment.setAttachSuffix(new StringBuffer(".").append(fileSuffix).toString());
attachment.setAttachCreated(DateUtil.date());
attachment.setAttachSize(HaloUtils.parseSize(new File(mediaPath,fileName).length()));
attachment.setAttachWh(HaloUtils.getImageWh(new File(mediaPath,fileName)));
attachmentService.saveByAttachment(attachment);
updateConst();
log.info("上传文件[" + fileName + "]到[" + mediaPath.getAbsolutePath() + "]成功");

View File

@ -52,13 +52,13 @@
<div class="form-group">
<label for="attachStorage" class="col-sm-2 control-label">附件大小:</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="attachStorage" disabled>
<input type="text" class="form-control" id="attachStorage" value="${attachment.attachSize?if_exists}" disabled>
</div>
</div>
<div class="form-group">
<label for="attachSize" class="col-sm-2 control-label">图片尺寸:</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="attachSize" disabled>
<input type="text" class="form-control" id="attachSize" value="${attachment.attachWh?if_exists}" disabled>
</div>
</div>
</div>
@ -121,17 +121,9 @@
}
$(document).ready(function(){
var clipboard = new Clipboard('.btn-copy');
var img = document.getElementsByTagName("img")[0];
//获取文件的大小和尺寸
var width = img.naturalWidth;
var height = img.naturalHeight;
var image = new Image();
image.src = img.src;
$('#attachSize').val(width+'x'+height);
$('#attachStorage').val('256k');
});
$('.btn-copy').click(function () {
showMsg("复制成功","success",1000)
})
</script>
</html>
</html>