2013-05-12 234 views
0

我希望能够调整图像斑点之前,我将它保存到与谷歌应用程序引擎数据库调整图像大小

from google.appengine.api import images 
from google.appengine.ext import blobstore 
from google.appengine.ext.webapp import blobstore_handlers 
from google.appengine.ext import db 

class ImageModel(db.Model): 
    image1 = blobstore.BlobReferencePropert(required = True) 


class UploadImageHandler(BaseHandler, blobstore_handlers.BlobstoreUploadHandler): 
    def post(self): 
      upload_files = self.get_uploads('image1') 
      blob_info = upload_files[0] 
      blob_key = blob_info.key() 
      img = images.Image(blob_key = blob_key) 
      img.resize(width = 500, height = 500) 

      i = ImageModel(image1 = img) 
      i.put() 

当然,这并不工作,因为IMG是没有更长的一滴。如何将图像转换回blob,然后上传到数据库。我不想动态提供图像并调整大小。我需要在数据库中有一个调整大小的图像。

回答

2

现在BLOBSTORE支持写文件直接 https://developers.google.com/appengine/docs/python/blobstore/overview#Writing_Files_to_the_Blobstore

这样你就可以有这样的事情。

# resize your img 

# create file 
file_name = files.blobstore.create(mime_type='application/octet-stream') 
with files.open(file_name, 'a') as f: 
    f.write(img)  

# Finalize the file. Do this before attempting to read it. 
files.finalize(file_name) 

# Get the file's blob key 
blob_key = files.blobstore.get_blob_key(file_name) 
+0

谢谢。我能够做我需要的。 – piyushg91 2013-05-12 17:47:31

+0

现在不推荐使用:( – Lipis 2013-08-17 18:05:14