| | |
| | | String filePath = pathHelper.getTempPath() + File.separator + oldName; |
| | | File newFile = new File(filePath); |
| | | file.transferTo(newFile); |
| | | long sizes = file.getSize(); |
| | | |
| | | // 获取MD5 |
| | | String md5 = getFileMd5(filePath); |
| | |
| | | return ctrl.success("文件已存在", md5); |
| | | } |
| | | |
| | | AttachEntity ae = getAttachEntity(ue, tab, oldName, md5); |
| | | AttachEntity ae = getAttachEntity(ue, tab, oldName, md5, sizes); |
| | | String targetPath = pathHelper.getConfig().getUploadPath() + File.separator + ae.getPath(); |
| | | newFile.renameTo(new File(targetPath)); |
| | | |
| | |
| | | return md5; |
| | | } |
| | | |
| | | protected AttachEntity getAttachEntity(UserEntity ue, String tab, String oldName, String md5) { |
| | | protected AttachEntity getAttachEntity(UserEntity ue, String tab, String oldName, String md5, long sizes) { |
| | | AttachEntity entity = new AttachEntity(); |
| | | entity.setName(oldName); |
| | | entity.setTab(tab); |
| | | entity.setGuid(md5); |
| | | String subPath = PathHelper.getUploadPath() + File.separator + md5; |
| | | entity.setPath(subPath); |
| | | entity.setSizes(sizes); |
| | | if (ue != null) { |
| | | entity.setCreateUser(ue.getId()); |
| | | } |
| | |
| | | fi.setSize(file.getSize()); |
| | | fi.setPath(path + File.separator + fi.getFileName()); |
| | | file.transferTo(new File(fi.getPath())); |
| | | fi.setMd5(getFileMd5(fi.getPath())); |
| | | |
| | | list.add(fi); |
| | | } |