Skip to content

Instantly share code, notes, and snippets.

@joshlong
Created March 13, 2013 18:16
Show Gist options
  • Select an option

  • Save joshlong/5154710 to your computer and use it in GitHub Desktop.

Select an option

Save joshlong/5154710 to your computer and use it in GitHub Desktop.
@RequestMapping(value = USER_COLLECTION_ENTRY_PHOTO_URL, method = RequestMethod.POST)
@ResponseBody
public Long uploadBasedOnPathVariable(@PathVariable("userId") Long userId, @RequestParam("file") MultipartFile file) throws Throwable {
byte[] bytesForImage = file.getBytes();
userService.writeUserProfilePhotoAndQueueForConversion(userId, file.getName(), bytesForImage);
return userId;
}
@RequestMapping(value = USER_COLLECTION_ENTRY_PHOTO_URL, method = RequestMethod.GET)
public void renderMedia(HttpServletResponse httpServletResponse, OutputStream os, @PathVariable("userId") Long userId) throws Throwable {
InputStream is = userService.readUserProfilePhoto(userId);
httpServletResponse.setContentType(MediaType.IMAGE_JPEG_VALUE);
if (null == is) {
return;
}
try {
IOUtils.copyLarge(is, os);
} finally {
IOUtils.closeQuietly(is);
IOUtils.closeQuietly(os);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment