BlobStore - 显示照片错误

时间:2015-06-22 16:32:50

标签: blobstore datastore

我有GWT / GAE MySQL云的经验。但我没有使用BlobStore。我必须添加到我的项目照片。为了理解BlobStore,我找到了一个例子:https://github.com/ikai/gwt-gae-image-gallery。但它不起作用。我有两个问题:

1.为什么servlet“UploadServlet”返回null为blob键:

public void doPost(HttpServletRequest req, HttpServletResponse res)
        throws ServletException, IOException {
        // Take uploaded image
    Map<String, List<BlobKey>> blobs = blobstoreService.getUploads(req);
    System.out.println("UPL.SERV.key size=" + blobs.size());
    List<BlobKey> blobKey = blobs.get("image");
    ImagesService imagesService = ImagesServiceFactory.getImagesService();
    String imageUrl = imagesService.getServingUrl(ServingUrlOptions.Builder.withBlobKey(blobKey.get(0))).trim();
    // Uploaded image object: key, servingUrl,createdAt, ownerId
    Entity uploadedImage = new Entity("UploadedImage");

    uploadedImage.setProperty("blobKey", blobKey.get(0).getKeyString().trim());
    uploadedImage.setProperty(UploadedImage.CREATED_AT, new Date());
    uploadedImage.setProperty(UploadedImage.OWNER_ID, "anna");

    // Highly unlikely we'll ever search on this property
    uploadedImage.setUnindexedProperty(UploadedImage.SERVING_URL, imageUrl);
    System.out.println("UPL.SERV-5- Z datastore key=" + keyString);
    res.sendRedirect("/upload?uploadedImageKey=" + keyString);
}

doPost重定向: UPL.SERV-5- key = aglub19hcHBfaWRyGgsSDVVwbG9hZGVkSW1hZ2UYgICAgICA4ggM     @覆盖     protected void doGet(HttpServletRequest req,HttpServletResponse resp)             抛出ServletException,IOException {

    System.out.println("UPL.SERV-6- req="+req.getParameter("uploadedImageKey"));
    String uploadedImageKey = req.getParameter("uploadedImageKey").trim();
    resp.setHeader("Content-Type", "text/html");

    // This is a bit hacky, but it'll work. We'll use this key in an Async
    // service to
    // fetch the image and image information
    System.out.println("UPL.SERV-7- resp="+uploadedImageKey);
    resp.getWriter().println(uploadedImageKey);
}

doGet得到: UPL.SERV-6- req = aglub19hcHBfaWRyGgsSDVVwbG9hZGVkSW1hZ2UYgICAgICA4ggM 并将答案发送到“UploadPhoto”: UPL.SERV-7- resp = aglub19hcHBfaWRyGgsSDVVwbG9hZGVkSW1hZ2UYgICAgICA4ggM

“UploadPhoto变为空。

  1. 为什么我不能显示我的照片?
  2. 在数据存储中存在:

    UPL.SERV-3 SET for datastore

    UPL.SERV -3-的BlobKey = 7cvGUXW_q9Q9QTEArWv3LA

    UPL.SERV -3-键= UploadedImage(无-ID-还)

    UPL.SERV -3-所有者=安娜

    UPL.SERV -3- URL = http://0.0.0.0:8888/_ah/img/7cvGUXW_q9Q9QTEArWv3LA

    UPL.SERV-4-放到数据存储区

    当创建小部件“ImageOverlay”时,我得到:

    7cvGUXW_q9Q9QTEArWv3LA = s200:1 GET http://0.0.0.0:8888/_ah/img/7cvGUXW_q9Q9QTEArWv3LA=s200 net :: ERR_ADDRESS_INVALID

1 个答案:

答案 0 :(得分:0)

它不起作用,因为开发模式中的doGet返回null。