title: How would you serve a Google cloud storage file from an appengine servlet?
body: <p>The user uploaded some files, that I stored in Google Cloud Storage. Now the user comes back and want to download a file from a list my app is showing. He/she clicks the link and a servlet is called. What the code behind that servlet would look like?
  Also, I don't want to make the objects publicly available.
  Here how mine would look like: 
  Is there a simpler way to do this?
  Thanks.</p>
  
  <pre><code>public class ServeGSObject extends HttpServlet {
      FileService fileService = FileServiceFactory.getFileService();
      public void doGet(HttpServletRequest request, HttpServletResponse response){
          String fullFilePath = request.getParameter("objectPath");
          AppEngineFile file = new AppEngineFile(fullFilePath);
          try {
              FileReadChannel channel = fileService.openReadChannel(file, false);
              BufferedInputStream bis = new BufferedInputStream(Channels.newInputStream(channel));
              BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream());
              response.setHeader("Content-Disposition", "inline;filename=\"" + file.getNamePart() + "");
              int b = 0;
              while((b = bis.read()) != -1) {
                  bos.write(b);
              }
              bos.flush();
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  }
  </code></pre>