| | |
| | | import com.sinata.appointment.constants.BizErrorCode; |
| | | import com.sinata.appointment.exception.BizException; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.nio.file.Files; |
| | | import java.nio.file.Path; |
| | | import java.nio.file.StandardCopyOption; |
| | |
| | | if (!target.getParent().equals(uploadDir)) { |
| | | throw new BizException(BizErrorCode.AUTH_FORBIDDEN, "图片上传路径非法"); |
| | | } |
| | | try { |
| | | try (InputStream in = file.getInputStream()) { |
| | | Files.createDirectories(uploadDir); |
| | | Files.copy(file.getInputStream(), target, StandardCopyOption.REPLACE_EXISTING); |
| | | Files.copy(in, target, StandardCopyOption.REPLACE_EXISTING); |
| | | } catch (IOException ex) { |
| | | throw new BizException(BizErrorCode.AUTH_FORBIDDEN, "图片上传失败"); |
| | | } |