I am trying to clone a template ( folder with nested sub-folders) , replace a few files , ZIP it up and serve it to the user. Can this be done in App Engine since there is no local storage?
*** UPDATE**** The difficulty there was to build out a directory structure in memory and then zipping it up. Fortunately I found this post on stackoverflow : java.util.zip - Recreating directory structure
The rest is trivial.
thanks All,
Yes, this can be done.
As I understand you, you want to serve a zip file. You don't need to save a zip file prior it is sent to the client as the response of a servlet. You can send the zip file directly to the client as it is generated / on-the-fly. (Note that AppEngine will cache the response and send it as the whole when your response is ready, but that's irrelevant here.)
Set the content type to
application/zip
, and you can create and send the response zip file by instantiating aZipOutputStream
passing the servlet's output stream as a constructor parameter.Here's an example how to do it with an
HttpServlet
:Note: You might wanna disable caching of your response zip file, depending on your case. If you want to disable caching the result by proxies and browsers, add these lines before you start the
ZipOutputStream
: