2

(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 をブロブストアにアップロードし、ブロブキーをキャプチャして、モデルへの参照を保存する手順はどのようにすればよいですか?

4

1 に答える 1

1

Blobstore API ドキュメントを読む

残念ながら、従来は Files API を使用してこれを行っていましたが、GCS の使用を支持して非推奨になっているため、次のことができます (不足している部分を埋めることができます): (この例から)

import cloudstorage as gcs
from google.appengine.ext import blobstore

class ImageModel(ndb.Model):
    image_filename = ndb.StringProperty(indexed=False)

    @property
    def imagetoserve(self):
        return blobstore.create_gs_key(self.image_filename)

BUCKET = "bucket_to_store_image\\"

with gcs.open(BUCKET + blob_info.filename, 'w', content_type='image/png') as f:
    f.write(imgtmp.execute_transforms())

img = ImageModel()
img.image_filename = BUCKET + blob_info.filename
img.put()
于 2013-08-09T19:36:23.480 に答える