1

我使用以下代码成功地将图像发布到我的 Google AppEngine 应用程序:

  def post(self):

    image_data = self.request.get('file')
    file_name = files.blobstore.create(mime_type='image/png')

    # Open the file and write to it
    with files.open(file_name, 'a', exclusive_lock=True) as f:
      f.write(image_data)

    # 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)
    self.response.out.write(images.get_serving_url( blob_key ))

但是,当我浏览由 输出的 URL 时get_serving_url(),图像始终处于降低的分辨率。为什么?我已经检查并仔细检查了发布的图像尺寸是否正确(来自 iPhone 相机,分辨率约为 3200x2400)。然而,提供的图像始终是 512x384。

我对 GAE 还很陌生,但我认为上面的代码应该将图像存储在 BlobStore 而不是数据存储中,从而绕过 1 MB 的限制。

有谁知道会发生什么?

干杯,布雷特

4

2 回答 2

3

找到了解决方案。或者至少对我有用的东西。我将附加=sXX到提供的 URL 的末尾,AppEngine 将以XX分辨率提供图像。例如,如果该行:

self.response.out.write(images.get_serving_url( blob_key ))

返回: http://appengine.sample.com/appengineurlkey

那么在调用上面的url结果的时候,图片会是分辨率较低的图片,

然后通过调用 URL: http://appengine.sample.com/appengineurlkey**=s1600**

生成的服务图像将具有1600x1200分辨率(或受保持纵横比限制的类似分辨率)。

于 2012-08-08T16:40:27.330 回答
0

https://developers.google.com/appengine/docs/python/images/functions中解释了您所看到的内容

在文档中get_serving_url

调整大小或裁剪图像时,您必须使用 0 到 1600 的整数指定新大小。最大大小在 IMG_SERVING_SIZES_LIMIT 中定义。API 将图像大小调整为提供的值,将指定大小应用于图像的最长尺寸并保留原始纵横比。

如果您想提供全尺寸图像,另一种方法是将您的图像直接上传到 blobstore,然后从那里提供它们。(即,完全绕过图像 API。)请参阅https://developers.google.com/appengine/docs/python/blobstore/overview

于 2012-08-08T17:18:05.970 回答