您好我正在开发 IOS 应用程序。我还使用 JSON Web 服务。我还使用 Google App Engine for python。我对 python 和谷歌应用引擎真的很陌生。我无法弄清楚这个问题;
我在 json 中发送 base64 图像和其他信息。我想将其他信息保存到数据库(GQL)并保存到图像谷歌文件夹(Blob 商店),并且这张照片 url 与谷歌数据库中的其他信息一起保存。
你能帮我吗thanx
更新
import cgi
import datetime
import time
import urllib
import wsgiref.handlers
import os, urllib2, re, base64
import simplejson as json
from google.appengine.ext import db
from google.appengine.api import users,images, files
from google.appengine.ext import webapp
from google.appengine.ext import blobstore
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext.webapp import template
from google.appengine.ext import blobstore
from google.appengine.ext.webapp import blobstore_handlers
import logging
class PanoMessages(db.Model):
first_name=db.StringProperty();
last_name=db.StringProperty();
msg_text=db.TextProperty();
photo_url=blobstore.BlobReferenceProperty();
class IOSDeneme(webapp.RequestHandler):
def post(self):
received_content = self.request.body;
try:
decoded_json = json.loads(received_content);
panoMsg=PanoMessages();
panoMsg.photo_url=save_image_to_blobstore(decoded_json["picture"],"image/png");
panoMsg.first_name=decoded_json["first_name"];
panoMsg.last_name=decoded_json["last_name"];
panoMsg.msg_text=decoded_json["msg_text"];
panoMsg.put();
self.response.out.write(json.dumps({'StatusCode':'2', 'StatusMessage':'OK'}));
except ValueError:
logging.error("json-time sent data which simplejson couldn't parse")
self.response.out.write(json.dumps({'StatusCode':'4', 'StatusMessage':'NO'}));
def save_image_to_blobstore(base64str, mimeType):
from google.appengine.api import files
import binascii
fileName1 = files.blobstore.create(mime_type=mimeType)
with files.open(fileName1, 'a') as f:
f.write(binascii.a2b_base64(base64str))
files.finalize(fileName1)
return files.blobstore.get_blob_key(fileName1)