From 829955f51107cab650e2cbdc2ce839525f21a5de Mon Sep 17 00:00:00 2001 From: Alvin Hermans Date: Mon, 8 Jun 2020 18:00:07 +0000 Subject: [PATCH 1/7] blobstore url fetch by script.js and display in html --- portfolio/pom.xml | 7 +++- .../servlets/BlobstoreUploadUrlServlet.java | 37 ++++++++++++++++++ .../sps/servlets/FormHandlerServlet.java | 0 portfolio/src/main/webapp/comments.html | 1 + portfolio/src/main/webapp/images.html | 38 +++++++++++++++++++ portfolio/src/main/webapp/index.html | 1 + portfolio/src/main/webapp/projects.html | 1 + portfolio/src/main/webapp/resume.html | 1 + portfolio/src/main/webapp/script.js | 12 ++++++ 9 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 portfolio/src/main/java/com/google/sps/servlets/BlobstoreUploadUrlServlet.java create mode 100644 portfolio/src/main/java/com/google/sps/servlets/FormHandlerServlet.java create mode 100644 portfolio/src/main/webapp/images.html diff --git a/portfolio/pom.xml b/portfolio/pom.xml index 1760dc3..1cc417c 100644 --- a/portfolio/pom.xml +++ b/portfolio/pom.xml @@ -23,6 +23,12 @@ 4.0.1 provided + + + com.google.appengine + appengine-api-1.0-sdk + 1.9.59 + @@ -36,7 +42,6 @@ halvin-step-2020 - 1 diff --git a/portfolio/src/main/java/com/google/sps/servlets/BlobstoreUploadUrlServlet.java b/portfolio/src/main/java/com/google/sps/servlets/BlobstoreUploadUrlServlet.java new file mode 100644 index 0000000..7cf5a84 --- /dev/null +++ b/portfolio/src/main/java/com/google/sps/servlets/BlobstoreUploadUrlServlet.java @@ -0,0 +1,37 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.sps.servlets; + +import com.google.appengine.api.blobstore.BlobstoreService; +import com.google.appengine.api.blobstore.BlobstoreServiceFactory; +import java.io.IOException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/* Web servlet that returns a fresh Blobstore upload URL */ +@WebServlet("/blobstore-upload-url") +public class BlobstoreUploadUrlServlet extends HttpServlet { + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { + BlobstoreService blobstore = BlobstoreServiceFactory.getBlobstoreService(); + String uploadUrl = blobstore.createUploadUrl("/form-handler"); + + response.setContentType("text/html"); + response.getWriter().println(uploadUrl); + } +} \ No newline at end of file diff --git a/portfolio/src/main/java/com/google/sps/servlets/FormHandlerServlet.java b/portfolio/src/main/java/com/google/sps/servlets/FormHandlerServlet.java new file mode 100644 index 0000000..e69de29 diff --git a/portfolio/src/main/webapp/comments.html b/portfolio/src/main/webapp/comments.html index 908f700..d77d7f9 100644 --- a/portfolio/src/main/webapp/comments.html +++ b/portfolio/src/main/webapp/comments.html @@ -17,6 +17,7 @@
  • projects
  • resume
  • +
  • images