title: How do I download a image file from google webapp engine?
body: <pre><code>AppEngineFile AFE = new AppEngineFile(FILESYSTEM + alist.get(0).getPath());
  BlobKey bk = FileServiceFactory.getFileService().getBlobKey(AFE);
  
  
  if("image/jpeg".equals(alist.get(0).getContentType()) ){
      resp.setContentType("image/jpeg");
  } 
  
  resp.setHeader("Content-Disposition", "attachment; filename=\"" + alist.get(0).getTitle() + "\"");
  
  FileService fileService = FileServiceFactory.getFileService();
  AppEngineFile file = null;
  
  try {
      file = fileService.getBlobFile(bk);
  } catch (FileNotFoundException e) {
      e.printStackTrace();
  }
  
  FileReadChannel ch = null;
  
  try {
      ch = fileService.openReadChannel(file, false);
  } catch (FileNotFoundException e) {
      e.printStackTrace();
  } catch (LockException e) {
      e.printStackTrace();
  } catch (IOException e) {
      e.printStackTrace();
  }
  
  byte[] barray = new byte[MAXSIZE];
  
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  
  try {
      ByteBuffer bb = ByteBuffer.wrap(barray);
      int nRead;
      while ((nRead=ch.read(bb)) != -1) {
          for (int i=0; i &lt; nRead; i++) {
              try {
                  baos.write(barray[i]);
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
          bb.clear();
      }
  } catch (IOException e) {
      e.printStackTrace();
  }
  
  resp.setContentLength(baos.size());
  
  // resp.getOutputStream().write(baos.toByteArray()); // &lt;= if I use it, this message, "Error 6 (net::ERR_FILE_NOT_FOUND): The file or directory could not be found.", is showed.
  
  // out.print(baos); // &lt;= if I use this, I can download a file but it is byte code.            
  
  baos.flush();
  baos.close();
  </code></pre>
  
  <p>How do I fix whole this code for downloading an image file? because If I use Number 1, it make a error, which is "Error 6 (net::ERR_FILE_NOT_FOUND): The file or directory could not be found.", is showed." or if i use number 2, it looks fine but the type of stored file is byte code. This means is not image file.</p>
  
  <p>Who can give me any idea or example?</p>