title: Spring Boot - REST API to Post file and return Zipped file in response
body: <p>Im trying to receive a file from an HTTP POST which I split into individual files wand then need to return that in a zip file.  I am trying to return the file and I have tried everything to return the file, but I am unable to recieve the file... any thoughts?  </p>
  
  <pre><code>@RequestMapping(value = "/splitFile", headers = ("content-type=multipart/*"), produces ="application/zip", method = RequestMethod.POST)
  public void SplitFile(@RequestParam(value = "file", required = true) MultipartFile[] file, HttpServletResponse response ) throws IOException {
  
  
  
      for (int i = 0; i &lt; file.length; i++) {
          File uplFile = new File(file[i].getOriginalFilename());
          uplFile.createNewFile();
          FileOutputStream fos = new FileOutputStream(uplFile);
          fos.write(file[i].getBytes());
          fos.close();
  
          System.out.println("Splitting File: " + uplFile.getName());
          uploadHelper Help = new uploadHelper();
  
          ArrayList&lt;String&gt; filestrings = new ArrayList&lt;String&gt;();
          filestrings = uplHelp.GetSplitFiles(uplFile);
  
  
          ByteArrayOutputStream out = new ByteArrayOutputStream();
          BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(out);
          ZipOutputStream zipOutputStream = new ZipOutputStream(bufferedOutputStream);
  
  
          StringBuilder sb = new StringBuilder();
          int filenumber = 0;
          for (String filedata : filestrings) {
              filenumber = filenumber + 1;
              sb.append(filedata);
              ZipEntry e = new ZipEntry("file_" + filenumber + ".data");
              zipOutputStream.putNextEntry(e);
  
              byte[] data = sb.toString().getBytes();
              zipOutputStream.write(data, 0, data.length);
              zipOutputStream.closeEntry();
  
  
          }
          System.out.println("Splitting File - Split " + filestrings.size() + " files");
  
          if (zipOutputStream != null) {
              zipOutputStream.finish();
              zipOutputStream.flush();
              IOUtils.closeQuietly(zipOutputStream);
          }
          IOUtils.closeQuietly(bufferedOutputStream);
          IOUtils.closeQuietly(out);
          InputStream is = new ByteArrayInputStream(out.toByteArray());
          response.setStatus(HttpServletResponse.SC_OK);
          response.addHeader("Content-Disposition", "attachment; filename=test.zip");
          response.setCharacterEncoding("gzip");
          org.apache.commons.io.IOUtils.copy(is, response.getOutputStream());
          response.flushBuffer();
  
  
      }
      response.setStatus(HttpServletResponse.SC_ACCEPTED);
      response.flushBuffer();
  
  
  }
  </code></pre>