0

I want to use the camera in my Android app to take a photo and then upload it to my GAE server.

This is the code I'm using to send the image:

var saveImageView = Titanium.UI.createImageView({
                top : 0,
                left : 0,
                width : 'auto',
                height : 'auto',
                image : event.media,
            });

            win1.add(saveImageView);
            imageToUpload = saveImageView.toBlob();
            // toBlob, not toImage!! important...
            var xhr = Titanium.Network.createHTTPClient();
            xhr.onload = function() {
                win1.remove(saveImageView);
                // remove the temp view...
            };
            xhr.open('POST', 'not sure what goes here');
            xhr.send({
                image : imageToUpload
            });

I'm not sure what I'm supposed to use as the server's web address.

Also, any help in what this should look like on the GAE side will be greatly helpful.

I have found this source: http://www.mstrinity.com/blog/2010/12/29/posting-an-image-from-titanium-to-the-app-engine-data-storage-serving-that-image-out/

But it's 4 years old, and I can't get it to work at all.

papercuts
  • 1,428
  • 4
  • 15
  • 16

1 Answers1

1

The posting an image from titanium article appears still valid after 4 years. The writer uses 'http://10.1.10.15:8888/addimage' where you have 'not sure what goes here'. This answer assumes you mainly want the URL explained.

The titanium code uses a private IP address to upload images from an Android device to the AppEngine development server (port 8888) on a private network. The development server must accept incoming connections from more than just localhost for this to work, see this answer for a way to achieve that. You will need to replace the IP address with that of your own AppEngine development computer, use ifconfig, ipconfig or similar to find that out.

The python code for the AppEngine server should work without modification, this answer assumes that you are comfortable with it.

After the software all works with the development server you will deploy to for example 'papercuts-image-gallery' in the AppEngine cloud. In the titanium code you should then replace the 10.1.10.15:8888 part with papercuts-image-gallery.appspot.com (without a port number) but keep the rest of the URL string. If I were you I would retain both URL strings in the titanium application code and select one using a flag, to easily point the client towards the development server or the production server without recompiling.

Community
  • 1
  • 1
Martin Berends
  • 3,948
  • 2
  • 16
  • 19
  • I can't seem to make the GAE code work as is. I have a bit of experience with GAE. Is there something I should be doing with the app.yaml file or similar to make it work? Thanks :) – papercuts Mar 08 '14 at 08:21
  • Yes, the article omitted to mention app.yaml. See the notes under Creating the Configuration File in [Hello, World!](https://developers.google.com/appengine/docs/python/gettingstartedpython27/helloworld) for guidance. In fact, put your project aside for a few minutes and run the tutorial first to verify the correct operation of your SDK. – Martin Berends Mar 08 '14 at 08:31