| | |
| | | @RequestMapping("upload")
|
| | | @Api(tags = "图片上传")
|
| | | public class ImageUploadController {
|
| | |
|
| | | @ApiOperation(value="上传图片")
|
| | | @ApiOperation(value="/image", notes = "上传图片")
|
| | | @RequestMapping(value = "/image", method = RequestMethod.POST)
|
| | | public CommonResult uploadImage(HttpServletRequest request, MultipartFile image) throws IOException {
|
| | |
|
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
|
| | |
|
| | | String filePath = "/images/" + sdf.format(new Date());
|
| | | String imageFolderPath = request.getServletContext().getRealPath(filePath);
|
| | | File imageFolder = new File(imageFolderPath);
|
| | |
| | | .append(request.getServerPort())
|
| | | .append(request.getContextPath())
|
| | | .append(filePath);
|
| | |
|
| | | String imageName = UUID.randomUUID() + "_" + image.getOriginalFilename().replaceAll(" ", "");
|
| | | try {
|
| | | IOUtils.write(image.getBytes(), new FileOutputStream(new File(imageFolder, imageName)));
|
| | |
| | | } catch (IOException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | return CommonResult.failed("上传失败!");
|
| | | return CommonResult.failed( "上传失败!");
|
| | | }
|
| | | }
|