How do i upload/stream large images using Spring 3.2 spring-mvc in a restful way

前端 未结 4 837
慢半拍i
慢半拍i 2020-12-13 19:48

I try to upload/stream a large image to a REST controller that takes the file and stores it in to a database.

@Controller
@RequestMapping(\"/api/member/pictu         


        
4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-13 20:07

    If you want do deal with the request body as an InputStream you can get it directly from the Request.

    @Controller
    @RequestMapping("/api/member/picture")
    public class MemberPictureResourceController {
    
        @RequestMapping(value = "", method = RequestMethod.POST)
        @ResponseStatus(HttpStatus.NO_CONTENT)
        public void addMemberPictureResource(HttpServletRequest request) {
            try {
                InputStream is = request.getInputStream();
                // Process and Store image in database
            } catch (IOException e) {
                // handle exception
            }
        }
    }
    

提交回复
热议问题