示例#1
0
  @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);
    }
  }
 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()));
 }