| | |
| | | |
| | | import com.matrix.core.tools.*; |
| | | import com.matrix.system.common.constance.AppConstance; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.FileCopyUtils; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import org.springframework.web.multipart.MultipartHttpServletRequest; |
| | |
| | | * @email 935090232@qq.com |
| | | * @date 2018年6月15日 |
| | | */ |
| | | @Component |
| | | public class UploadUtil { |
| | | @Value("${file_storage_path}") |
| | | private String fileStoragePath; |
| | | |
| | | @Value("${static_resource_url}") |
| | | private String staticResourceUrl; |
| | | |
| | | private static String STATUSS = "status"; |
| | | private static String MSG = "msg"; |
| | |
| | | * @throws IOException |
| | | */ |
| | | |
| | | public static Map<String, String> doUpload(MultipartHttpServletRequest request, List<FileType> extList, |
| | | public Map<String, String> doUpload(MultipartHttpServletRequest request, List<FileType> extList, |
| | | String folderType, Long userId) throws NoSuchAlgorithmException, IOException { |
| | | Map<String, String> resourceMap = new HashMap<>(); |
| | | |
| | | // 图片保存目录路径 |
| | | String baseSavePath = PropertiesUtil.getString(AppConstance.FILES_TORAGE_PATH); |
| | | String baseSavePath =fileStoragePath; |
| | | // 图片保存目录URL |
| | | String baseSaveUrl = PropertiesUtil.getString(AppConstance.NGINX_URL); |
| | | String baseSaveUrl = staticResourceUrl; |
| | | LogUtil.debug("图片保存目录路径={}",baseSavePath); |
| | | LogUtil.debug("图片保存目录URL={}",baseSaveUrl); |
| | | |
| | |
| | | String newFileName = UUIDUtil.getRandomID() + "." + fileExt; |
| | | Map<String, String> fileUrlMap = fileUrl(baseSavePath, baseSaveUrl, folderType, userId); |
| | | String savePath = fileUrlMap.get("savePath"); |
| | | String saveUrl = fileUrlMap.get("saveUrl"); |
| | | String saveUrl = fileUrlMap.get("saveUrl").replaceAll("\\\\","/"); |
| | | File uploadedFile = new File(savePath, newFileName); |
| | | try { |
| | | FileCopyUtils.copy(file.getBytes(), uploadedFile); |