2

URLを指定すると、ファイルがダウンロードされ、ブロブストアにブロブとして保存されるプロセスをGAEを使用して作成したいと考えています。これが完了したら、このブロブを POST データとして 2 番目の URL に渡したいと思います。ただし、この 2 番目の部分が機能するには、BLOB をファイル インスタンスとして開くことができる必要があります。

最初の部分のやり方が分かった

from __future__ import with_statement
from google.appengine.api import files

imagefile = urllib2.urlopen('fileurl')
# Create the file
file_name = files.blobstore.create(mime_type=imagefile.headers['Content-Type'])
# Open the file and write to it
with files.open(file_name, 'ab') as f:
    f.write(imagefile.read())
# 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)

しかし、2番目の部分を行う方法がわかりません。これまで私は試しました

  1. ffile = files.open(files.blobstore.get_file_name(blob_key), 'r')

  2. from google.appengine.ext import blobstore

    ffile = blobstore.BlobReader(blob_key)
    
  3. from google.appengine.ext import blobstore

    ffile = blobstore.BlobInfo.open(blobstore.BlobInfo(blob_key))
    

そのすべてが を与えFalseますisinstance(ffile, file)

どんな助けでも大歓迎です。

4

2 に答える 2

2

ffile = blobstore.BlobReader(blob_key)動作します。ただし、返されたオブジェクトにはファイルのようなインターフェイスしかありません。ファイルクラスを拡張しません。したがって、isinstance テストは機能しません。のようなものを試してくださいif ffile and "read" in dir( ffile )

于 2013-01-09T10:43:33.987 に答える
1

blobstore から file_data を読み取るには:

blob_key = .....                                        # is what you have
file_name = blobstore.BlobInfo.get(blob_key).filename   # the name of the file (image) to send 
blob_reader = blobstore.BlobReader(blob_key)
file_data = blob_reader.read()                          # and the file data with the image

ただし、blob_key を使用して URL を送信し、その URL を提供することもできます。また、画像の場合は、get_serving_url を投稿して、動的スケーリングで Google High Performance Image Serving API を利用できるため、自分で画像を提供する必要はありません。この方法で画像を提供することも非常に安価です。

このような URL の例を次に示します。

https://lh6.ggpht.com/lOghqU2JrYk8M-Aoio8WjMM6mstgZcTP0VzJk79HteVLhnwZy0kqbgVGQZYP8YsoqVNzsu0EBysX16qMJe7H2BsOAr4j=s70

于 2013-01-09T14:23:15.527 に答える