I'm building an android app that posts a picture to a GAE web service.
I created the web service and tested it with a simple HTML form to
submit a picture and a few other fields. This works perfectly. I then
implemented everything for the android app and posting the image with
the other form data to the web service works fine when testing against
my local GAE dev server. When I test against my deployed GAE app, I
get a NPE when trying to retrieve the blobkey for the request.

The android app first obtains the URL that it can post to (I use a
HttpGet to do this). Once it has the post URL, I create a
HttpURLConnection based on that and write the image and the form
fields.

Has anyone run into this?

Here is the relevant portion of my controllers:
@Controller
@RequestMapping("/listings")
public class ListingController {
        private static final Logger logger =
Logger.getLogger(ListingController.class.getName());
        private final BlobstoreService blobstoreService =
BlobstoreServiceFactory
                        .getBlobstoreService();

        private static final String BLOB_UPLOAD_PATH = "/api/listings/post";
        private static final String BLOB_UPLOAD_REDIRECT = "/api/listings/
listing/";
        private static final String IMAGE_INPUT_NAME = "imageFile";
        private static final String LAT_LONG_SEPERATOR = ",";
        private static final String SPACE = " ";
        private static final OutputEncoding IMAGE_FORMAT =
OutputEncoding.JPEG;
        private static final int IMAGE_RESIZE_WIDTH = 800;
        private static final int IMAGE_RESIZE_HEIGHT = 600;
        private static final int THUMB_RESIZE_WIDTH = 100;
        private static final int THUMB_RESIZE_HEIGHT = 75;
        private static final char HASH_TAG_DELIM = '#';

        @RequestMapping(value = "/post/path", method = RequestMethod.GET)
        @ResponseBody
        public String postPath() {
                return gson.toJson(new Text(blobstoreService
                                .createUploadUrl(BLOB_UPLOAD_PATH)));
        }

        @RequestMapping(value = "/post", method = RequestMethod.POST)
        @ResponseBody
        public void post(@RequestParam("lat") String latitude,
                        @RequestParam("lng") String longitude,
                        @RequestParam("desc") String description,
                        @RequestParam("categories") String[] categories,
                        HttpServletRequest request, HttpServletResponse 
response)
                        throws IOException {
                Map<String, BlobKey> blobs =
blobstoreService.getUploadedBlobs(request);
                BlobKey blobKey = blobs.get(IMAGE_INPUT_NAME);
                logger.info("blob key="+blobKey);
                BlobInfoFactory bif = new BlobInfoFactory();
                BlobInfo bi = bif.loadBlobInfo(blobKey);
                logger.info("blob size="+bi.getSize());

                ImagesService imagesService =
ImagesServiceFactory.getImagesService();
                Image original = 
ImagesServiceFactory.makeImageFromBlob(blobKey);
                logger.info("original image=" + original);
                Image originalForThumb = ImagesServiceFactory
                                .makeImageFromBlob(blobKey);
                Transform resize =
ImagesServiceFactory.makeResize(IMAGE_RESIZE_WIDTH,
                                IMAGE_RESIZE_HEIGHT);
                Transform thumbnailResize = ImagesServiceFactory.makeResize(
                                THUMB_RESIZE_WIDTH, THUMB_RESIZE_HEIGHT);
                Image resizedImage = imagesService.applyTransform(resize, 
original,
                                IMAGE_FORMAT);
                Image resizedThumb = 
imagesService.applyTransform(thumbnailResize,
                                originalForThumb, IMAGE_FORMAT);

                GeoPt location = new GeoPt(Float.valueOf(latitude), Float
                                .valueOf(longitude));
                Blob image = new Blob(resizedImage.getImageData());
                Blob thumb = new Blob(resizedThumb.getImageData());

                Text desc = new Text(description);
                String address = "";
                Set<String> tags = getTagsFromDesc(description);

                Listing l = new Listing(getCategories(categories), tags, new 
Date(),
                                location, address, desc, image, thumb);
                l = listingDao.create(l);

                blobstoreService.delete(blobKey);

                response.sendRedirect(BLOB_UPLOAD_REDIRECT
                                + KeyFactory.keyToString(l.getKey()));
        }
}

Thanks,

Tristan

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.

Reply via email to