package com.google.sps.servlets;

import com.google.sps.workspace.Workspace;
import com.google.sps.workspace.WorkspaceFactory;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/workspace/downloadWorkspace")
public class DownloadWorkspace extends HttpServlet {
  WorkspaceFactory workspaceFactory;

  @Override
  public void init() throws ServletException {
    // TODO Auto-generated method stub
    super.init();
    workspaceFactory = WorkspaceFactory.getInstance();
  }

  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    Workspace w = workspaceFactory.fromWorkspaceID(req.getParameter("workspaceID"));

    resp.setContentType("application/x-gzip");

    try {
      w.getArchive().archive(resp.getOutputStream());
    } catch (InterruptedException | ExecutionException e) {
      resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
  }
}

@@ -45,39 +45,174 @@
 .google.
-sps.workspace.Workspace
+appengine.api.blobstore.BlobKey;%0Aimport com.google.appengine.api.blobstore.BlobstoreService;%0Aimport com.google.appengine.api.blobstore.BlobstoreServiceFactory
 ;%0Aimport
@@ -287,56 +287,8 @@
 on;%0A
-import java.util.concurrent.ExecutionException;%0A
 impo
@@ -924,55 +924,28 @@
     
-Workspace w = workspaceFactory.fromWorkspaceID(
+String downloadID = 
 req.
@@ -962,22 +962,20 @@
 er(%22
-workspace
+download
 ID%22)
-)
 ;%0A%0A 
@@ -1029,201 +1029,270 @@
     
-try %7B%0A      w.getArchive().archive(resp.getOutputStream());%0A    %7D catch (InterruptedException %7C ExecutionException e) %7B%0A      resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);%0A    %7D
+BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();%0A    BlobKey blobKey =%0A        blobstoreService.createGsBlobKey(%0A            %22/gs/fulfillment-deco-step-2020.appspot.com/%22 + downloadID);%0A    blobstoreService.serve(blobKey, resp);
 %0A  %7D

Update download servlet to pull from cloud storage.