(1) jpg をブロブストアにアップロードする、Python で書かれた GAE に関するページがあります。その部分は機能します。(2)I'm Feeling Lucky Image 変換を実行し、(3)別のブロブとしてブロブストアに保存する必要があります。理想的には、(1)、(2)、および (3) を同じ Upload Handler で実行したいと考えています。
ここのコードに従いましたが、(1) と (2) しか実行しません。 https://developers.google.com/appengine/docs/python/images/#Python_Transforming_images_from_the_Blobstore
私はSOを見てきましたが、私が見つけることができる最も近いものはこれです: Storing Filtered images on the blobstore in GAE
(ファイル API を使用して) 変換をファイルに保存し、そのファイルをブロブストアにアップロードします。ただし、Files API を使用しており、次のように、Files API は非推奨です。 https://developers.google.com/appengine/docs/python/blobstore/#Python_Writing_files_to_the_Blobstore
私のモデルには、画像への参照をブロブストアに保存する BlobKeyProperty があります
class ImageModel(ndb.Model):
imagetoserve = ndb.BlobKeyProperty(indexed=False)
ここまでのアップロード ハンドラ コードは次のとおりです。
from google.appengine.ext import blobstore
from google.appengine.ext.webapp import blobstore_handlers
from google.appengine.api.images import get_serving_url
from google.appengine.api import images
upload_files = self.get_uploads('imgfile') # 'file' is file upload field in the form
blob_info = upload_files[0]
imgtmp = images.Image(blob_info)
imgtmp.im_feeling_lucky()
img = ImageModel()
img.imagetoserve = imgtmp
img.put()
私の問題はこの行にあります:
img.imagetoserve = imgtmp
モデルは blobkey プロパティですが、画像を入力しているため、明らかに型の不一致のようなエラーが発生します。変換された imgtmp をブロブストアにアップロードし、ブロブキーをキャプチャして、モデルへの参照を保存する手順はどのようにすればよいですか?