Example usage for org.springframework.http MediaType IMAGE_JPEG

List of usage examples for org.springframework.http MediaType IMAGE_JPEG

Introduction

In this page you can find the example usage for org.springframework.http MediaType IMAGE_JPEG.

Prototype

MediaType IMAGE_JPEG

To view the source code for org.springframework.http MediaType IMAGE_JPEG.

Click Source Link

Document

Public constant media type for image/jpeg .

Usage

From source file:com.github.carlomicieli.nerdmovies.utility.ImageUtils.java

private static void validateFile(MultipartFile file) throws IOException {
    String contentType = file.getContentType();
    if (!contentType.equals(MediaType.IMAGE_JPEG.toString())
            && !contentType.equals(MediaType.IMAGE_PNG.toString()))
        throw new IOException("Invalid media type");
}

From source file:com.trenako.web.images.ThumbnailatorServiceTests.java

@Test
public void shouldCreateImages() throws Exception {
    final byte[] content = "file content".getBytes();
    MultipartFile file = mockFile(content, MediaType.IMAGE_JPEG);

    UploadFile img = imgConverter.createImage(file, metadata());

    assertNotNull(img.getContent());//  ww w .  j a va  2s  . c  o m
    assertEquals(MediaType.IMAGE_JPEG_VALUE.toString(), img.getContentType());
}

From source file:org.openmrs.module.patientimage.rest.controller.PatientImageController.java

/**
 * @param patientid int//from  w  ww  .j a  va 2  s  . c o  m
 * @param pageid int
 * @return ResponseEntity<byte[]> containing image binary data with JPEG
 *    image header.
 * @throws ResponseException
 * @throws IOException 
 */
@RequestMapping(value = "/{patientid}/{pageid}", method = RequestMethod.GET)
public ResponseEntity<byte[]> retrieve(@PathVariable("patientid") String patientIdStr,
        @PathVariable("pageid") String pageIdStr, HttpServletRequest request) throws IOException {
    //RequestContext context = RestUtil.getRequestContext(request);
    int patientId = Integer.parseInt(patientIdStr);
    int pageId = Integer.parseInt(pageIdStr);
    final HttpHeaders headers = new HttpHeaders();
    byte[] imageData = null;
    HttpStatus status = null;
    headers.setContentType(MediaType.IMAGE_JPEG);
    status = HttpStatus.OK;
    return new ResponseEntity<byte[]>(imageData, headers, status);
}

From source file:ai.emot.api.impl.EmotionTemplate.java

@Override
public EmotionProfile getFaceImageEmotionProfile(BufferedImage image) {

    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
    headers.setContentType(MediaType.IMAGE_JPEG);
    HttpEntity<BufferedImage> entity = new HttpEntity<BufferedImage>(image, headers);

    ResponseEntity<EmotionProfile> response = restTemplate.exchange(apiBaseUrl + "/face/emotion",
            HttpMethod.POST, entity, EmotionProfile.class);
    return response.getBody();

}

From source file:com.trenako.web.images.WebImageServiceTests.java

@Test
public void shouldRenderImages() {
    GridFSDBFile mockFile = mock(GridFSDBFile.class);
    when(mockFile.getContentType()).thenReturn(MediaType.IMAGE_JPEG.toString());
    when(mockFile.getInputStream()).thenReturn(new ByteArrayInputStream(new byte[] {}));

    when(repo.findFileBySlug(eq("img-slug"))).thenReturn(mockFile);

    ResponseEntity<byte[]> resp = service.renderImage("img-slug");

    assertNotNull(resp);//from   w  w  w.j a  v a2  s . c  o m
    assertTrue(resp.hasBody());
    assertEquals(HttpStatus.CREATED, resp.getStatusCode());
    assertEquals(MediaType.IMAGE_JPEG, resp.getHeaders().getContentType());
}

From source file:net.bafeimao.umbrella.web.test.controller.CaptchaControllerTests.java

/**
 * ??/*from w ww  . ja va 2s.  c  o  m*/
 */
@Test
public void testBuildCaptcha() throws Exception {
    this.mockMvc.perform(get("/captcha").accept(MediaType.IMAGE_JPEG)).andExpect(status().isOk())
            .andExpect(content().contentType("image/jpeg"));
}

From source file:fi.helsinki.opintoni.web.rest.publicapi.PublicImageResource.java

@RequestMapping(value = "/avatar/{oodiPersonId}", method = RequestMethod.GET, produces = MediaType.IMAGE_JPEG_VALUE)
public ResponseEntity<BufferedImage> getUserAvatarByOodiPersonId(
        @PathVariable("oodiPersonId") String oodiPersonId) throws IOException {
    return ResponseEntity.ok().headers(headersWithContentType(MediaType.IMAGE_JPEG))
            .body(userSettingsService.getUserAvatarImageByOodiPersonId(oodiPersonId));
}

From source file:com.github.dactiv.fear.service.web.SystemCommonController.java

/**
 * ?????/*from   w  w  w . j a  va  2  s.  c  om*/
 *
 * @param token ??
 *
 * @return ?? byte 
 *
 * @throws IOException
 */
@RequestMapping("get-captcha")
public ResponseEntity<byte[]> getCaptcha(JpegImgCaptchaToken token, HttpSession session) throws IOException {
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.IMAGE_JPEG);

    captchaManager.setCurrentSession(session);
    Captcha captcha = captchaManager.create(token);

    return new ResponseEntity<>(captcha.getStream(), headers, HttpStatus.OK);
}

From source file:com.greglturnquist.HomeController.java

private ResponseEntity<?> getRawImage() {
    try {//from   w w w.ja  v a2  s .c o m
        Resource file = resourceLoader.getResource("file:upload-dir/keep-calm-and-learn-javascript.jpg");
        return ResponseEntity.ok().contentLength(file.contentLength()).contentType(MediaType.IMAGE_JPEG)
                .body(new InputStreamResource(file.getInputStream()));
    } catch (IOException e) {
        return ResponseEntity.badRequest().body("Couldn't find it => " + e.getMessage());
    }
}

From source file:fi.helsinki.opintoni.web.rest.publicapi.PublicImageResource.java

@RequestMapping(value = "/background/{oodiPersonId}", method = RequestMethod.GET, produces = MediaType.IMAGE_JPEG_VALUE)
public ResponseEntity<BufferedImage> getUserBackgroundByOodiPersonId(
        @PathVariable("oodiPersonId") String oodiPersonId) throws IOException {
    return ResponseEntity.ok().headers(headersWithContentType(MediaType.IMAGE_JPEG))
            .body(userSettingsService.getUserBackgroundImage(oodiPersonId));
}