BlobStore - display photo error

51 views Asked by At

I have experience with GWT/GAE MySQL cloud. But I don’t with BlobStore. I have to add to my project photos. To understand BlobStore I found an example: https://github.com/ikai/gwt-gae-image-gallery. But it doesn’t work. I have 2 problems:

1.Why the servlet “UploadServlet” return null as a blob key:

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 redirect : UPL.SERV-5- key=aglub19hcHBfaWRyGgsSDVVwbG9hZGVkSW1hZ2UYgICAgICA4ggM @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws 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 gets : UPL.SERV-6- req=aglub19hcHBfaWRyGgsSDVVwbG9hZGVkSW1hZ2UYgICAgICA4ggM And send answer to “UploadPhoto”: UPL.SERV-7- resp=aglub19hcHBfaWRyGgsSDVVwbG9hZGVkSW1hZ2UYgICAgICA4ggM

“UploadPhoto gets null.

  1. Why I can’t to display my photo?

In datastore exists:

UPL.SERV-3- SET for datastore

UPL.SERV-3-blobkey=7cvGUXW_q9Q9QTEArWv3LA

UPL.SERV-3-key=UploadedImage(no-id-yet)

UPL.SERV-3-owner=anna

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

UPL.SERV-4- put to datastore

When the widget with is created “ImageOverlay” I get:

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

1

There are 1 answers

0
user2258777 On

It doesn't work because doGet in development mode return null.