| | |
| | | package com.lf.server.service.all; |
| | | |
| | | import com.lf.server.entity.data.MetaEntity; |
| | | import com.lf.server.entity.data.MetaFileEntity; |
| | | import com.lf.server.helper.FileHelper; |
| | | import com.lf.server.helper.PathHelper; |
| | | import com.lf.server.helper.StringHelper; |
| | |
| | | /** |
| | | * 上传文件 |
| | | */ |
| | | public <T> List<MetaEntity> uploadData(T t, String path, HttpServletRequest req, HttpServletResponse res) throws Exception { |
| | | public <T> List<MetaFileEntity> uploadData(T t, String path, HttpServletRequest req, HttpServletResponse res) throws Exception { |
| | | StandardMultipartHttpServletRequest request = (StandardMultipartHttpServletRequest) req; |
| | | req.setCharacterEncoding("utf-8"); |
| | | res.setContentType("application/json;charset=utf-8"); |
| | |
| | | if (t != null) { |
| | | setEntity(t, request); |
| | | } |
| | | List<MetaEntity> list = getFiles(path, request); |
| | | |
| | | return list; |
| | | return getFiles(path, request); |
| | | } |
| | | |
| | | /** |
| | |
| | | /** |
| | | * 获取文件 |
| | | */ |
| | | public List<MetaEntity> getFiles(String subPath, StandardMultipartHttpServletRequest req) throws Exception { |
| | | List<MetaEntity> list = new ArrayList<MetaEntity>(); |
| | | public List<MetaFileEntity> getFiles(String subPath, StandardMultipartHttpServletRequest req) throws Exception { |
| | | List<MetaFileEntity> list = new ArrayList<>(); |
| | | |
| | | String path = pathHelper.getTempPath(subPath); |
| | | Iterator<String> iterator = req.getFileNames(); |
| | | while (iterator.hasNext()) { |
| | | MultipartFile file = req.getFile(iterator.next()); |
| | | if (StringHelper.isEmpty(file.getOriginalFilename())) { |
| | | if (null == file || StringHelper.isEmpty(file.getOriginalFilename())) { |
| | | continue; |
| | | } |
| | | |
| | | double sizes = FileHelper.sizeToMb(file.getSize()); |
| | | MetaEntity mf = new MetaEntity(); |
| | | MetaFileEntity mf = new MetaFileEntity(); |
| | | mf.setName(file.getOriginalFilename()); |
| | | |
| | | double sizes = FileHelper.sizeToMb(file.getSize()); |
| | | mf.setSizes(sizes); |
| | | mf.setPath(path + File.separator + mf.getName()); |
| | | |