I noticed that I was making an item registration and editing function. With the current api, multiple images will be uploaded with one api. The transmission time is very long and the user experience is poor.
I checked Mercari (http://mercari.jp) to see how other apps are doing around here. Mercari seems to upload to the server every time one image is selected.
That's why I tried to imitate it. The uploader is complete. I thought I was touching Mercari, but someday I would like to add an image processing function as well!
#Image upload
class PutImage(UserLoginAuthRequestHandler):
def post(self):
if self.invalidateAccount():
Common.writeUserResponseError(self, 401,u"Invalid session")
return
blob = self.request.get('blob')
content_type = self.request.params['blob'].type
blobHash = hashlib.md5(blob).hexdigest()
gcsPath = Common.createImagePath(blobHash)
Common.saveToGCS(gcsPath,blob,content_type)
entity = ImageFile()
entity.path = gcsPath
entity.md5 = blobHash
entity.put()
res = dict(
url = webapp2.uri_for('GetImage',_full=True,imageid=entity.key.id())
)
Common.writeUserResponseSuccess(self, res )
#Returns the specified image
class GetImage(UserLoginAuthRequestHandler):
def get(self):
imageid = int(self.request.get('imageid'))
item = ImageFile.get_by_id(imageid)
path = item.path
gcs_file = gcs.open(path)
gcs_stat = gcs.stat(path)
self.response.content_type = gcs_stat.content_type
self.response.content_type_params = None
self.response.write(gcs_file.read())
gcs_file.close()
app = webapp2.WSGIApplication(
[
webapp2.Route('/user/api/resource/putimage', PutImage,'PutImage'),
webapp2.Route('/user/api/resource/getimage', GetImage,'GetImage'),
],
debug=Common.isDebug()
)
With this kind of feeling, the registration / editing function of circle items has been added. https://github.com/nagai/freemarket/tree/20140429 Next time, we will create a spot sale venue.
Recommended Posts