|
@ -33,7 +33,61 @@ import com.yihu.wlyy.web.BaseController;
|
|
@RequestMapping(value = "/upload", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
|
|
@RequestMapping(value = "/upload", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
|
|
@Api(description = "文件上传")
|
|
@Api(description = "文件上传")
|
|
public class FileUploadController extends BaseController {
|
|
public class FileUploadController extends BaseController {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 患者头像上传
|
|
|
|
* @return
|
|
|
|
* @throws IOException
|
|
|
|
* @throws IllegalStateException
|
|
|
|
*/
|
|
|
|
@RequestMapping(value = "patientPhoto", method = RequestMethod.POST/* , headers = "Accept=image/png" */)
|
|
|
|
@ResponseBody
|
|
|
|
public String patientPhoto(HttpServletRequest request, HttpServletResponse response,String photo) {
|
|
|
|
// 圖片列表
|
|
|
|
//List<File> images = new ArrayList<File>();
|
|
|
|
//List<String> tempPaths = new ArrayList<String>();
|
|
|
|
// 文件保存的临时路径
|
|
|
|
//String tempPath = SystemConf.getInstance().getImagePath() + File.separator;
|
|
|
|
// 拼接年月日路径
|
|
|
|
//String datePath = DateUtil.getStringDate("yyyy") + File.separator + DateUtil.getStringDate("MM") + File.separator + DateUtil.getStringDate("dd") + File.separator;
|
|
|
|
try {
|
|
|
|
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
|
|
|
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
|
|
|
|
// 创建文件夹
|
|
|
|
//File file = new File(tempPath + datePath);
|
|
|
|
//if (!file.exists()) {
|
|
|
|
// file.mkdirs();
|
|
|
|
//}
|
|
|
|
String fileName = null;
|
|
|
|
String firstPhoto=null;
|
|
|
|
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
|
|
|
|
// 上传文件
|
|
|
|
MultipartFile mf = entity.getValue();
|
|
|
|
fileName = mf.getOriginalFilename();
|
|
|
|
String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
|
|
|
|
// 重命名文件
|
|
|
|
firstPhoto=photo.substring(0,photo.lastIndexOf("."))+"_small."+fileExt;
|
|
|
|
File uploadFile = new File(firstPhoto);
|
|
|
|
// 拷贝文件流到指定文件路径
|
|
|
|
FileCopyUtils.copy(mf.getBytes(), uploadFile);
|
|
|
|
// 生成缩略图
|
|
|
|
//ImageCompress.compress(uploadFile.getAbsolutePath(), uploadFile.getAbsolutePath() + "_small", 300, 300);
|
|
|
|
// 添加到上传成功数组中
|
|
|
|
//images.add(uploadFile);
|
|
|
|
//tempPaths.add(datePath + newFileName);
|
|
|
|
}
|
|
|
|
String urls = firstPhoto;
|
|
|
|
JSONObject json = new JSONObject();
|
|
|
|
json.put("status", 200);
|
|
|
|
json.put("msg", "上传成功");
|
|
|
|
// 图片标识对象的HTTP链接
|
|
|
|
json.put("urls", urls);
|
|
|
|
System.out.println("图片上传:" + json.toString());
|
|
|
|
return json.toString();
|
|
|
|
} catch (Exception e) {
|
|
|
|
error(e);
|
|
|
|
return error(-1, "上传失败");
|
|
|
|
}
|
|
|
|
}
|
|
/**
|
|
/**
|
|
* 图片上传
|
|
* 图片上传
|
|
* @return
|
|
* @return
|
|
@ -243,4 +297,5 @@ public class FileUploadController extends BaseController {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|