【问题标题】:Serving blobstore images through SSL通过 SSL 提供 blobstore 图像
【发布时间】:2014-05-05 05:38:26
【问题描述】:

为我们的域添加 SSL 后,我开始看到这些警告:

The page at 'https://www.mydomain.com' was loaded over HTTPS, but displayed insecure content from 'http://lh6.ggpht.com/SfTsfy6g-LC2F_GNdiw12s8agFUjcTPB1AzCJon-dIfTG1zaKGHH9tk6be--gOIg-ubWoFuTAbdlo': this content should also be loaded over HTTPS.

通过 SSL 提供这些图像的最佳方式是什么。目前我有很多 Jinja2 模板引用这样的图像:

{{blobstore_image}}

我可以像这样简单地将 http 替换为 https:

{{blobstore_image|replace('http', 'https'}}

但是有没有办法总是从服务处理程序的send_blob() 返回 https 链接?

谢谢。

【问题讨论】:

    标签: google-app-engine ssl blobstore


    【解决方案1】:

    如果您使用get_serving_url() 方法提供图像,则可以指定secure_url=True

    from google.appengine.api import images
    
    image_serving_url = images.get_serving_url(blob_key, secure_url=True)
    

    这将返回一个带有 SSL 的服务 URL。

    文档:https://cloud.google.com/appengine/docs/standard/python/refdocs/google.appengine.api.images#Image_get_serving_url

    【讨论】:

    • 谢谢!似乎这是在我最初发布问题之后添加的。
    【解决方案2】:

    您可以从链接中删除http: 部分,它会自动按照您的页面所服务的协议提供链接。

    所以链接看起来像这样:

    //www.yourdomain.com/foobar

    【讨论】:

    • 是的,那应该比替换它更好。谢谢!我只是想知道是否有一种方法可以自动执行此操作,因为send_blob() 总是以http 返回它。
    • 不认为那是可能的。但你可以在将变量发送到模板之前这样做
    猜你喜欢
    • 2013-03-11
    • 2016-07-22
    • 2014-04-29
    • 2014-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-08
    • 2014-01-29
    相关资源
    最近更新 更多