开发者

Can Google App Engine be used for "check for updated" and download binary file web service?

开发者 https://www.devze.com 2023-01-01 08:00 出处:网络
I\'m a Google App Engine newbie and would be grateful for any help. I have an iPhone app which sources da开发者_开发技巧ta from an sqlite db stored localling on the device.

I'm a Google App Engine newbie and would be grateful for any help. I have an iPhone app which sources da开发者_开发技巧ta from an sqlite db stored localling on the device.

I'd like to set up a Google App Engine web service which my iPhone client will talk to and check if there is a newer version of the sqlite database it needs to download.

So iPhone client hits the web service with some kind of version number/timestamp and if there is a newer file, the App Engine will notify the client and the client will then request the new database to download which the App Engine will serve.

Is it possible to set up a web service in Google App Engine to do this? Could anyone point me to any sample code / tutorials please?

Many Thanks


What I would do is keep the SQLite DB as a gzipped blob in the datastore. Use the SHA1 hash as an etag. The client does a GET request with the etag header, and the server either responds with a 304 Not Modified or a 200 and the blob contents in the response body.

There is an API specifically for blobs, called the Blobstore API, but to use it you need to have billing enabled. Without billing enabled you can still easily serve blobs, but you'll be limited to 10MB per request, response, and entity size. If your zipped database is larger than that, you could conceivably break up the download into multiple requests, since you control both the client and server code. A custom blob handler that just uses the datastore might look like this:

class MyModel(db.Model):
  body = db.BlobProperty()

class MyBlobHandler(webapp.RequestHandler):
  def get(self):
    entity_key = self.request.get("entity_key")
    entity = MyModel.get(entity_key)
    self.response.headers['Content-type'] = 'what/ever'
    self.response.out.write(entity.body)
  def put(self):
    entity = MyModel(body=db.Blob(self.request.body))
    entity.put()
    self.response.out.write(entity.key())


This is entirely possible with App Engine, given that you're making HTTP requests.

The best code and tutorials, in my opinion, is the official Google App Engine docs. Everything you'll need is there.

0

精彩评论

暂无评论...
验证码 换一张
取 消