mirror of https://github.com/halo-dev/halo
👽 halo_attachment表新增attach_size和attach_wh,上传附件会保存附件大小和尺寸
parent
3e262390ea
commit
c6a4b2de20
|
@ -60,4 +60,14 @@ public class Attachment implements Serializable {
|
|||
* 上传时间
|
||||
*/
|
||||
private Date attachCreated;
|
||||
|
||||
/**
|
||||
* 附件大小
|
||||
*/
|
||||
private String attachSize;
|
||||
|
||||
/**
|
||||
* 附件长宽
|
||||
*/
|
||||
private String attachWh;
|
||||
}
|
||||
|
|
|
@ -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 "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有主题
|
||||
*
|
||||
|
|
|
@ -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() + "]成功");
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue