| | |
| | | |
| | | |
| | | import com.ycl.jxkg.base.BaseApiController; |
| | | import com.ycl.jxkg.base.RestResponse; |
| | | import com.ycl.jxkg.base.Result; |
| | | import com.ycl.jxkg.service.FileUpload; |
| | | import com.ycl.jxkg.service.UserService; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | |
| | | |
| | | @RequiredArgsConstructor |
| | | @RequestMapping("/api/student/upload") |
| | | @RestController("StudentUploadController") |
| | | public class UploadController extends BaseApiController { |
| | |
| | | private final FileUpload fileUpload; |
| | | private final UserService userService; |
| | | |
| | | @Autowired |
| | | public UploadController(FileUpload fileUpload, UserService userService) { |
| | | this.fileUpload = fileUpload; |
| | | this.userService = userService; |
| | | } |
| | | |
| | | |
| | | @RequestMapping("/image") |
| | | @ResponseBody |
| | | public RestResponse questionUploadAndReadExcel(HttpServletRequest request) { |
| | | public Result questionUploadAndReadExcel(HttpServletRequest request) { |
| | | MultipartHttpServletRequest multipartHttpServletRequest = (MultipartHttpServletRequest) request; |
| | | MultipartFile multipartFile = multipartHttpServletRequest.getFile("file"); |
| | | long attachSize = multipartFile.getSize(); |
| | |
| | | try (InputStream inputStream = multipartFile.getInputStream()) { |
| | | String filePath = fileUpload.uploadFile(inputStream, attachSize, imgName); |
| | | userService.changePicture(getCurrentUser(), filePath); |
| | | return RestResponse.ok(filePath); |
| | | return Result.ok(filePath); |
| | | } catch (IOException e) { |
| | | return RestResponse.fail(2, e.getMessage()); |
| | | return Result.fail(2, e.getMessage()); |
| | | } |
| | | } |
| | | |