Java Code Examples for org.springframework.http.MediaType#IMAGE_JPEG_VALUE

The following examples show how to use org.springframework.http.MediaType#IMAGE_JPEG_VALUE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HomeController.java    From Learning-Spring-Boot-2.0-Second-Edition with MIT License 6 votes vote down vote up
@GetMapping(value = BASE_PATH + "/" + FILENAME + "/raw",
	produces = MediaType.IMAGE_JPEG_VALUE)
@ResponseBody
public Mono<ResponseEntity<?>> oneRawImage(
							@PathVariable String filename) {
	return imageService.findOneImage(filename)
		.map(resource -> {
			try {
				return ResponseEntity.ok()
					.contentLength(resource.contentLength())
					.body(new InputStreamResource(
						resource.getInputStream()));
			} catch (IOException e) {
				return ResponseEntity.badRequest()
					.body("Couldn't find " + filename +
						" => " + e.getMessage());
			}
		});
}
 
Example 2
Source File: HomeController.java    From Learning-Spring-Boot-2.0-Second-Edition with MIT License 6 votes vote down vote up
@GetMapping(value = BASE_PATH + "/" + FILENAME + "/raw",
	produces = MediaType.IMAGE_JPEG_VALUE)
@ResponseBody
public Mono<ResponseEntity<?>> oneRawImage(
	@PathVariable String filename) {
	// tag::try-catch[]
	return imageService.findOneImage(filename)
		.map(resource -> {
			try {
				return ResponseEntity.ok()
					.contentLength(resource.contentLength())
					.body(new InputStreamResource(
						resource.getInputStream()));
			} catch (IOException e) {
				return ResponseEntity.badRequest()
					.body("Couldn't find " + filename +
						" => " + e.getMessage());
			}
		});
	// end::try-catch[]
}
 
Example 3
Source File: HomeController.java    From Learning-Spring-Boot-2.0-Second-Edition with MIT License 6 votes vote down vote up
@GetMapping(value = BASE_PATH + "/" + FILENAME + "/raw",
	produces = MediaType.IMAGE_JPEG_VALUE)
@ResponseBody
public Mono<ResponseEntity<?>> oneRawImage(
	@PathVariable String filename) {
	// tag::try-catch[]
	return imageService.findOneImage(filename)
		.map(resource -> {
			try {
				return ResponseEntity.ok()
					.contentLength(resource.contentLength())
					.body(new InputStreamResource(
						resource.getInputStream()));
			} catch (IOException e) {
				return ResponseEntity.badRequest()
					.body("Couldn't find " + filename +
						" => " + e.getMessage());
			}
		});
	// end::try-catch[]
}
 
Example 4
Source File: UploadController.java    From Learning-Spring-Boot-2.0-Second-Edition with MIT License 6 votes vote down vote up
@GetMapping(value = BASE_PATH + "/" + FILENAME + "/raw",
	produces = MediaType.IMAGE_JPEG_VALUE)
@ResponseBody
public Mono<ResponseEntity<?>> oneRawImage(
	@PathVariable String filename) {
	// tag::try-catch[]
	return imageService.findOneImage(filename)
		.map(resource -> {
			try {
				return ResponseEntity.ok()
					.contentLength(resource.contentLength())
					.body(new InputStreamResource(
						resource.getInputStream()));
			} catch (IOException e) {
				return ResponseEntity.badRequest()
					.body("Couldn't find " + filename +
						" => " + e.getMessage());
			}
		});
	// end::try-catch[]
}
 
Example 5
Source File: UploadController.java    From Learning-Spring-Boot-2.0-Second-Edition with MIT License 6 votes vote down vote up
@GetMapping(value = BASE_PATH + "/" + FILENAME + "/raw",
	produces = MediaType.IMAGE_JPEG_VALUE)
@ResponseBody
public Mono<ResponseEntity<?>> oneRawImage(
	@PathVariable String filename) {
	// tag::try-catch[]
	return imageService.findOneImage(filename)
		.map(resource -> {
			try {
				return ResponseEntity.ok()
					.contentLength(resource.contentLength())
					.body(new InputStreamResource(
						resource.getInputStream()));
			} catch (IOException e) {
				return ResponseEntity.badRequest()
					.body("Couldn't find " + filename +
						" => " + e.getMessage());
			}
		});
	// end::try-catch[]
}
 
Example 6
Source File: UploadController.java    From Learning-Spring-Boot-2.0-Second-Edition with MIT License 6 votes vote down vote up
@GetMapping(value = BASE_PATH + "/" + FILENAME + "/raw",
	produces = MediaType.IMAGE_JPEG_VALUE)
@ResponseBody
public Mono<ResponseEntity<?>> oneRawImage(
	@PathVariable String filename) {
	// tag::try-catch[]
	return imageService.findOneImage(filename)
		.map(resource -> {
			try {
				return ResponseEntity.ok()
					.contentLength(resource.contentLength())
					.body(new InputStreamResource(
						resource.getInputStream()));
			} catch (IOException e) {
				return ResponseEntity.badRequest()
					.body("Couldn't find " + filename +
						" => " + e.getMessage());
			}
		});
	// end::try-catch[]
}
 
Example 7
Source File: HomeController.java    From Learning-Spring-Boot-2.0-Second-Edition with MIT License 6 votes vote down vote up
@GetMapping(value = BASE_PATH + "/" + FILENAME + "/raw",
	produces = MediaType.IMAGE_JPEG_VALUE)
@ResponseBody
public Mono<ResponseEntity<?>> oneRawImage(
	@PathVariable String filename) {
	return imageService.findOneImage(filename)
		.map(resource -> {
			try {
				return ResponseEntity.ok()
					.contentLength(resource.contentLength())
					.body(new InputStreamResource(
						resource.getInputStream()));
			} catch (IOException e) {
				return ResponseEntity.badRequest()
					.body("Couldn't find " + filename +
						" => " + e.getMessage());
			}
		});
}
 
Example 8
Source File: HomeController.java    From Learning-Spring-Boot-2.0-Second-Edition with MIT License 6 votes vote down vote up
@GetMapping(value = BASE_PATH + "/" + FILENAME + "/raw",
	produces = MediaType.IMAGE_JPEG_VALUE)
@ResponseBody
public Mono<ResponseEntity<?>> oneRawImage(
	@PathVariable String filename) {
	// tag::try-catch[]
	return imageService.findOneImage(filename)
		.map(resource -> {
			try {
				return ResponseEntity.ok()
					.contentLength(resource.contentLength())
					.body(new InputStreamResource(
						resource.getInputStream()));
			} catch (IOException e) {
				return ResponseEntity.badRequest()
					.body("Couldn't find " + filename +
						" => " + e.getMessage());
			}
		});
	// end::try-catch[]
}
 
Example 9
Source File: HomeController.java    From Learning-Spring-Boot-2.0-Second-Edition with MIT License 6 votes vote down vote up
@GetMapping(value = BASE_PATH + "/" + FILENAME + "/raw",
	produces = MediaType.IMAGE_JPEG_VALUE)
@ResponseBody
public Mono<ResponseEntity<?>> oneRawImage(
	@PathVariable String filename) {
	// tag::try-catch[]
	return imageService.findOneImage(filename)
		.map(resource -> {
			try {
				return ResponseEntity.ok()
					.contentLength(resource.contentLength())
					.body(new InputStreamResource(
						resource.getInputStream()));
			} catch (IOException e) {
				return ResponseEntity.badRequest()
					.body("Couldn't find " + filename +
						" => " + e.getMessage());
			}
		});
	// end::try-catch[]
}
 
Example 10
Source File: HomeController.java    From Learning-Spring-Boot-2.0-Second-Edition with MIT License 6 votes vote down vote up
@GetMapping(value = BASE_PATH + "/" + FILENAME + "/raw",
	produces = MediaType.IMAGE_JPEG_VALUE)
@ResponseBody
public Mono<ResponseEntity<?>> oneRawImage(
	@PathVariable String filename) {
	// tag::try-catch[]
	return imageService.findOneImage(filename)
		.map(resource -> {
			try {
				return ResponseEntity.ok()
					.contentLength(resource.contentLength())
					.body(new InputStreamResource(
						resource.getInputStream()));
			} catch (IOException e) {
				return ResponseEntity.badRequest()
					.body("Couldn't find " + filename +
						" => " + e.getMessage());
			}
		});
	// end::try-catch[]
}
 
Example 11
Source File: HomeController.java    From Learning-Spring-Boot-2.0-Second-Edition with MIT License 6 votes vote down vote up
@GetMapping(value = BASE_PATH + "/" + FILENAME + "/raw",
	produces = MediaType.IMAGE_JPEG_VALUE)
@ResponseBody
public Mono<ResponseEntity<?>> oneRawImage(
	@PathVariable String filename) {
	// tag::try-catch[]
	return imageService.findOneImage(filename)
		.map(resource -> {
			try {
				return ResponseEntity.ok()
					.contentLength(resource.contentLength())
					.body(new InputStreamResource(
						resource.getInputStream()));
			} catch (IOException e) {
				return ResponseEntity.badRequest()
					.body("Couldn't find " + filename +
						" => " + e.getMessage());
			}
		});
	// end::try-catch[]
}
 
Example 12
Source File: HomeController.java    From Learning-Spring-Boot-2.0-Second-Edition with MIT License 6 votes vote down vote up
@GetMapping(value = BASE_PATH + "/" + FILENAME + "/raw",
	produces = MediaType.IMAGE_JPEG_VALUE)
@ResponseBody
public Mono<ResponseEntity<?>> oneRawImage(
							@PathVariable String filename) {
	return imageService.findOneImage(filename)
		.map(resource -> {
			try {
				return ResponseEntity.ok()
					.contentLength(resource.contentLength())
					.body(new InputStreamResource(
						resource.getInputStream()));
			} catch (IOException e) {
				return ResponseEntity.badRequest()
					.body("Couldn't find " + filename +
						" => " + e.getMessage());
			}
		});
}
 
Example 13
Source File: UploadController.java    From Learning-Spring-Boot-2.0-Second-Edition with MIT License 6 votes vote down vote up
@GetMapping(value = BASE_PATH + "/" + FILENAME + "/raw",
	produces = MediaType.IMAGE_JPEG_VALUE)
@ResponseBody
public Mono<ResponseEntity<?>> oneRawImage(
	@PathVariable String filename) {
	// tag::try-catch[]
	return imageService.findOneImage(filename)
		.map(resource -> {
			try {
				return ResponseEntity.ok()
					.contentLength(resource.contentLength())
					.body(new InputStreamResource(
						resource.getInputStream()));
			} catch (IOException e) {
				return ResponseEntity.badRequest()
					.body("Couldn't find " + filename +
						" => " + e.getMessage());
			}
		});
	// end::try-catch[]
}
 
Example 14
Source File: UploadController.java    From Learning-Spring-Boot-2.0-Second-Edition with MIT License 6 votes vote down vote up
@GetMapping(value = BASE_PATH + "/" + FILENAME + "/raw",
	produces = MediaType.IMAGE_JPEG_VALUE)
@ResponseBody
public Mono<ResponseEntity<?>> oneRawImage(
	@PathVariable String filename) {
	// tag::try-catch[]
	return imageService.findOneImage(filename)
		.map(resource -> {
			try {
				return ResponseEntity.ok()
					.contentLength(resource.contentLength())
					.body(new InputStreamResource(
						resource.getInputStream()));
			} catch (IOException e) {
				return ResponseEntity.badRequest()
					.body("Couldn't find " + filename +
						" => " + e.getMessage());
			}
		});
	// end::try-catch[]
}
 
Example 15
Source File: HomeController.java    From Learning-Spring-Boot-2.0-Second-Edition with MIT License 6 votes vote down vote up
@GetMapping(value = BASE_PATH + "/" + FILENAME + "/raw",
	produces = MediaType.IMAGE_JPEG_VALUE)
@ResponseBody
public Mono<ResponseEntity<?>> oneRawImage(
	@PathVariable String filename) {
	return imageService.findOneImage(filename)
		.map(resource -> {
			try {
				return ResponseEntity.ok()
					.contentLength(resource.contentLength())
					.body(new InputStreamResource(
						resource.getInputStream()));
			} catch (IOException e) {
				return ResponseEntity.badRequest()
					.body("Couldn't find " + filename +
						" => " + e.getMessage());
			}
		});
}
 
Example 16
Source File: TvSeriesController.java    From tutorial with MIT License 5 votes vote down vote up
/**
 * 返回某电视剧的图标
 * 这是一个返回非JSON格式(图片)格式的例子
 * @param id
 * @return
 */
@GetMapping(value="/{id}/icon", produces=MediaType.IMAGE_JPEG_VALUE)
public byte[] getIcon(@PathVariable int id) throws Exception{
    if(log.isTraceEnabled()) {
        log.trace("getIcon(" + id + ")");
    }
    String iconFile = "src/test/resources/icon.jpg";
    InputStream is = new FileInputStream(iconFile);
    return IOUtils.toByteArray(is);
}
 
Example 17
Source File: TvSeriesController.java    From tutorial with MIT License 5 votes vote down vote up
/**
 * 返回某电视剧的图标
 * 这是一个返回非JSON格式(图片)格式的例子
 * @param id
 * @return
 */
@GetMapping(value="/{id}/icon", produces=MediaType.IMAGE_JPEG_VALUE)
public byte[] getIcon(@PathVariable int id) throws Exception{
    if(log.isTraceEnabled()) {
        log.trace("getIcon(" + id + ")");
    }
    String iconFile = "src/test/resources/icon.jpg";
    InputStream is = new FileInputStream(iconFile);
    return IOUtils.toByteArray(is);
}
 
Example 18
Source File: CommonController.java    From mica-example with Apache License 2.0 4 votes vote down vote up
@ApiOperation("图片验证码-jpg")
@GetMapping(value = "captcha.jpg", produces = MediaType.IMAGE_JPEG_VALUE)
public Mono<ResponseEntity<Resource>> captchaJpg(ServerWebExchange exchange) {
	return Mono.just(micaCaptcha.generate(exchange));
}
 
Example 19
Source File: ImageGalleryController.java    From fredbet with Creative Commons Attribution Share Alike 4.0 International 4 votes vote down vote up
@GetMapping(value = "/showthumb/{imageKey}", produces = MediaType.IMAGE_JPEG_VALUE)
public ResponseEntity<byte[]> showThumbnail(@PathVariable("imageKey") String imageKey, WebRequest webRequest) {
    return createResponseEntityForImageId(imageKey, webRequest,
            imageAdministrationService -> imageAdministrationService.loadThumbnailByImageKey(imageKey));
}
 
Example 20
Source File: CommonController.java    From mica-example with Apache License 2.0 4 votes vote down vote up
@ApiOperation("图片验证码-jpg图片")
@GetMapping(value = "captcha.jpg", produces = MediaType.IMAGE_JPEG_VALUE)
public ResponseEntity<Resource> captchaJpg(HttpServletResponse response) {
	return micaCaptcha.generate(response);
}