看起来好像您在使用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()创建。当然,您也可以发布图像以创建图像资源。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)