【问题标题】:Transformed image from GAE Images API upload to Facebook从 GAE 图像 API 上传到 Facebook 的转换图像
【发布时间】:2012-07-19 23:30:59
【问题描述】:

有谁知道如何将 GAE Images API Image 对象转换为“类似文件的对象”?

我正在尝试上传从 GAE 图片 API 转换到 Facebook 的图片。我正在使用 execute_transforms 函数,它返回图像的“图像表示”。 我尝试使用以下代码上传它,但我得到一个 FB API 错误“没有上传的图像”

img = images.Image(ORIGINAL_IMAGE)
img.crop(0.0, 5.0/img.height, 713.0/img.width, 644.0/img.height)
output = img.execute_transforms(output_encoding=images.PNG)
graph = fb.GraphAPI(access_token)
graph.put_photo(output, 'Look at this cool photo!')

我认为问题在于 output 不是 put_photo 所需要的“类文件对象”,但 GAE 文档没有转换为“类文件对象”的功能.尝试创建临时文件并写入它们,但 GAE 不允许写入文件系统。我也尝试写入 StringIO 对象,但没有成功。

谢谢

【问题讨论】:

    标签: python image google-app-engine facebook-graph-api


    【解决方案1】:

    使用 StringIO

    enter code here
    
    import StringIO
    
    graph.put_photo(StringIO.StringIO(output), 'Look at this cool photo!')
    

    阅读http://docs.python.org/library/stringio.html的文档

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-12-11
      • 2012-09-02
      • 2016-03-27
      • 2012-05-23
      • 2022-01-22
      • 1970-01-01
      • 2014-05-07
      相关资源
      最近更新 更多