title: Bootstrap BlueImp file upload Java Controller Resolved
body: <p>I have added <a href="https://github.com/blueimp/jQuery-File-Upload" rel="nofollow">BlueImp Jquery multiple fileupload</a> to my project. 
  The server side of the download uses PHP, but I want to use a Java Controller.</p>
  
  <p>I've changed Blueimp's main.js to send the files to my controller - 'saveImages'. This part works and now it is sent to my Java controller.</p>
  
  <pre><code>$(function () {
      'use strict';
  
      // Initialize the jQuery File Upload widget:
      $('#fileupload').fileupload({
          // Uncomment the following to send cross-domain cookies:
          //xhrFields: {withCredentials: true},
          url: 'saveImages'
      });
  </code></pre>
  
  <p>When selecting/uploading an image,
  The headers show:</p>
  
  <pre><code>Connection  close
  Content-Length  5717
  Content-Type    text/html;charset=utf-8
  Date    Wed, 26 Mar 2014 19:43:42 GMT
  Server  Apache-Coyote/1.1
  Request Headers
  Accept  application/json, text/javascript, */*; q=0.01
  Accept-Encoding gzip, deflate
  Accept-Language en-US,en;q=0.5
  Content-Length  94000
  Content-Type    multipart/form-data; boundary=-------------------------- 
  </code></pre>
  
  <p>The Post Information shows:</p>
  
  <pre><code>-----------------------------1873186311532063957277019191 
  Content-Disposition: form-data; 
  name="files[]"; 
  filename="1.jpg" 
  Content-Type: image/jpeg 
  ÿØÿà�JFIF��`�`��ÿá�Exif��II*����������ÿÛ�C�ÿÛ�CÿÀ���"�ÿÄ����������������� ÿÄ�����������������ÿÄ�����������������ÿÄ�����������������ÿÚ���?�¿ÿÙ 
  -----------------------------1873186311532063957277019191-- 
  </code></pre>
  
  <p>This is the response from a PHP server - but I need to know how to do it with Java</p>
  
  <pre><code>{"files":[{"url":"http://jquery-file-upload.appspot.com/AMIfv97t6a-7QLgNXnhcK10mnbBojaAwHAL2oei6ySkhR_DKk6k5kDrS_tVhlAxFnCkYncEBM3IyeZ6n_oKXItO9dhoxcizw15pPtlA3-i53vc02Oh62RSqEdbK4QLvPwsFGdBOBmCjoNu8TOfl6m0eu1-Tquspryi48UOPXNe4eRfyrEJmBlJM/1.jpg",
  "thumbnailUrl":"http://lh4.ggpht.com/b5ABUz-uqTUynXXNvHSlYcAj3nRnlYVIEAhcSZKWXHcwI_jaDZCaNDuNK-gPjeiIMy9nUIAiwS5l1o3IttA5MikPJOEXkQjFCg=s80",
  "name":"1.jpg",
  "type":"image/jpeg",
  "size":309,
  "deleteUrl":"http://jquery-file-upload.appspot.com/AMIfv97t6a-7QLgNXnhcK10mnbBojaAwHAL2oei6ySkhR_DKk6k5kDrS_tVhlAxFnCkYncEBM3IyeZ6n_oKXItO9dhoxcizw15pPtlA3-i53vc02Oh62RSqEdbK4QLvPwsFGdBOBmCjoNu8TOfl6m0eu1-Tquspryi48UOPXNe4eRfyrEJmBlJM/1.jpg?delete=true",
  "deleteType":"DELETE"}]}
  </code></pre>
  
  <p>JSON</p>
  
  <pre><code>POST http://jquery-file-upload.appspot.com/
  
  200 OK
      2.06s   
  POST http://jquery-file-upload.appspot.com/
  
  200 OK
      1.18s   
  HeadersPostResponseJSON
  Sort by key
  
  
  files
  [Object { url="http://jquery-file-uplo...PXNe4eRfyrEJmBlJM/1.jpg",    thumbnailUrl="http://lh4.ggpht.com/b5...IttA5MikPJOEXkQjFCg=s80", name="1.jpg", more...}]
  
  0
  Object { url="http://jquery-file-uplo...PXNe4eRfyrEJmBlJM/1.jpg", thumbnailUrl="http://lh4.ggpht.com/b5...IttA5MikPJOEXkQjFCg=s80", name="1.jpg", more...}
  
  url
  "http://jquery-file-upload.appspot.com/AMIfv97t6a-7QLgNXnhcK10mnbBojaAwHAL2oei6ySkhR_DKk6k5kDrS_tVhlAxFnCkYncEBM3IyeZ6n_oKXItO9dhoxcizw15pPtlA3-i53vc02Oh62RSqEdbK4QLvPwsFGdBOBmCjoNu8TOfl6m0eu1-Tquspryi48UOPXNe4eRfyrEJmBlJM/1.jpg"
  
  thumbnailUrl
  "http://lh4.ggpht.com/b5ABUz-uqTUynXXNvHSlYcAj3nRnlYVIEAhcSZKWXHcwI_jaDZCaNDuNK-gPjeiIMy9nUIAiwS5l1o3IttA5MikPJOEXkQjFCg=s80"
  
  name
  "1.jpg"
  
  type
  "image/jpeg"
  
  size
  309
  
  deleteUrl
  "http://jquery-file-upload.appspot.com/AMIfv97t6a-7QLgNXnhcK10mnbBojaAwHAL2oei6ySkhR_DKk6k5kDrS_tVhlAxFnCkYncEBM3IyeZ6n_oKXItO9dhoxcizw15pPtlA3-i53vc02Oh62RSqEdbK4QLvPwsFGdBOBmCjoNu8TOfl6m0eu1-Tquspryi48UOPXNe4eRfyrEJmBlJM/1.jpg?delete=true"
  
  deleteType
  "DELETE"
  </code></pre>
  
  <h1>RESOLVED</h1>
  
  <pre><code>@RequestMapping(value = "saveImages", method = RequestMethod.POST, headers = "Accept=application/json")
  public String saveImages(HttpServletRequest request,
          HttpServletResponse response,
          @RequestPart("files") MultipartFile files, @RequestBody String x)
          throws Exception {
  
      ByteArrayInputStream in = new ByteArrayInputStream(files.getBytes());
      BufferedImage img = ImageIO.read(in);
  
      ByteArrayOutputStream buffer = new ByteArrayOutputStream();
  
  ........
  </code></pre>
  
  <h1>I resolved this myself and have updated the Controller to reflect it. I hope it helps others. If my answer isn't the most efficient, I would appreciate any comments. Thanks.</h1>
  
  <p>My environment:</p>
  
  <ul>
  <li><p>Java 1.6</p></li>
  <li><p>Spring 4.0.2.RELEASE, </p></li>
  <li><p>Twitter Bootstrap v3.1.1</p></li>
  <li><p>Maven 2.4.1</p></li>
  </ul>