如何使用Spring 3.2 spring-mvc以宁静的方式上传流式传输大图像

如何使用Spring 3.2 spring-mvc以宁静的方式上传流式传输大图像,第1张

如何使用Spring 3.2 spring-mvc以宁静的方式上传/流式传输大图像

看起来好像您在使用spring一样,您可以使用HttpEntity(http://static.springsource.org/spring/docs/3.1.x/javadoc-
api/org/springframework/http/HttpEntity.html
)。

使用它,您将得到如下所示(看一下“有效载荷”):

@Controllerpublic class ImageServerEndpoint extends AbstractEndpoint {@Autowired private ImagemetadataFactory metaDataFactory;@Autowired private FileService fileService;@RequestMapping(value="/product/{spn}/image", method=RequestMethod.PUT) public ModelAndView handleImageUpload(        @PathVariable("spn") String spn,        HttpEntity<byte[]> requestEntity,         HttpServletResponse response) throws IOException {    byte[] payload = requestEntity.getBody();    HttpHeaders headers = requestEntity.getHeaders();    try {        ProductImagemetadata metaData = metaDataFactory.newSpnInstance(spn, headers);        fileService.store(metaData, payload);        response.setStatus(HttpStatus.NO_CONTENT.value());        return null;    } catch (IOException ex) {        return internalServerError(response);    } catch (IllegalArgumentException ex) {        return badRequest(response, "Content-Type missing or unknown.");    }}

我们在这里使用PUT是因为它是RESTfull“将图像放入产品”。“
spn”是产品编号,图像名称由fileService.store()创建。当然,您也可以发布图像以创建图像资源。



欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5441842.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-11
下一篇 2022-12-11

发表评论

登录后才能评论

评论列表(0条)

保存