@ResponseBody @RequestMapping(value = "/admin/upload.ajax", method = RequestMethod.POST) public ResponseEntity<byte[]> upload( @RequestParam("restaurantId") String restaurantId, @RequestParam("file") CommonsMultipartFile file) throws Exception { Map<String, Object> model = new HashMap<String, Object>(); try { S3Object object = new S3Object(basePath + "/" + restaurantId); object.setDataInputStream(file.getInputStream()); object.setContentLength(file.getSize()); object.setContentType(file.getContentType()); S3Bucket bucket = s3Service.getBucket(bucketName); s3Service.putObject(bucket, object); Restaurant restaurant = restaurantRepository.findByRestaurantId(restaurantId); restaurant.setHasUploadedImage(true); restaurantRepository.saveRestaurant(restaurant); model.put("success", true); } catch (Exception ex) { LOGGER.error("", ex); model.put("success", false); model.put("message", ex.getMessage()); } String json = jsonUtils.serializeAndEscape(model); final HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.TEXT_HTML); headers.setCacheControl("no-cache"); return new ResponseEntity<byte[]>(json.getBytes("utf-8"), headers, HttpStatus.OK); }