I want to serve a dynamic zip file with multiple user uploaded images that are stored in blobstorage
I'm successfuly doing it with the following code, but I encounter a problem where the Appengine instances are being terminated because they consume too much memory.
is it possible to serve such zip files by streaming them directly to the client and not keeping them in the memory? is there another solution?
w.Header().Set("Content-Type", "application/zip")
w.Header().Set("Content-Disposition", "attachment;filename=photos.zip")
writer := zip.NewWriter(w)
defer writer.Close()
for _, key := range l.Files {
info, err := blobstore.Stat(c, appengine.BlobKey(key))
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
wr, err := writer.Create(info.Filename)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
reader := blobstore.NewReader(c, appengine.BlobKey(key))
io.Copy(wr, reader)
}