コード例 #1
0
ファイル: ImageServlet.java プロジェクト: nurinamu/gcplab
  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
    String blobKey = req.getParameter("blobKey");
    String path = req.getParameter("path");

    if (path != null && path.trim().length() > 0) {
      JsonObject retObj = new JsonObject();

      String uploadBlobPath =
          BlobstoreServiceFactory.getBlobstoreService()
              .createUploadUrl(URLDecoder.decode(path), UploadOptions.Builder.withDefaults());

      retObj.addProperty("result", "success");
      retObj.addProperty("path", URLEncoder.encode(uploadBlobPath));

      if (retObj.get("result") == null) {
        retObj.addProperty("result", "fail");
      }

      resp.getWriter().write(retObj.toString());
    } else if (blobKey != null) {
      BlobstoreServiceFactory.getBlobstoreService().serve(new BlobKey(blobKey), resp);
    }
  }
コード例 #2
0
 public static String getUploadUrl(ImageRef ref) {
   BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
   return blobstoreService.createUploadUrl(
       "/backend/image-post-upload?ref=" + BaseEncoding.base64().encode(ref.toByteArray()),
       UploadOptions.Builder.withGoogleStorageBucketName(getBucket()));
 }