Google App Engine 本地开发服务器不路由到远程云存储桶

Google App Engine Local Dev Server Does not Route to Remote Cloud Storage Bucket

我正在尝试通过 dev_appserver.py 开发服务器访问托管在远程云存储桶上的文件。

直接link到google云存储有效:

https://leanplum-wordpress.storage.googleapis.com/leanplum-black.svg

因为本地通过 dev_appserver 没有:

http://localhost:8080/_ah/gcs/leanplum-black.svg

日志输出:

INFO     2016-07-06 22:37:16,461 module.py:788] default: "GET /_ah/gcs/leanplum-black.svg HTTP/1.1" 200 116

我是运行这样的开发服务器:

dev_appserver.py --default_gcs_bucket_name=leanplum-wordpress .

怎么了?

您需要确保使用您的 google 云项目配置身份验证,并且客户端将连接到生产 google 云存储而不是本地开发(默认情况下发生)当检测到本地开发服务器 运行 时)。

here

我们仍然遇到这个问题。我们认为这是一个源自 Appengine Wordpress 插件的问题。

我们想出了以下解决方法来正确加载图像:

在 Google Chrome 中创建一个小书签并添加以下内容 url:

javascript:var start = var targetUrls = ["//" + window.location.host + "/wp-content/uploads/","//" + window.location.host + "/_ah/gcs/bucket-name/"];var htmlAttributes = ["src", "srcset"];jQuery("img").each(function(index, img) {targetUrls.forEach(function(pattern) {htmlAttributes.forEach(function(htmlAttr) {var htmlObj = jQuery(img).attr(htmlAttr);if (htmlObj) {jQuery(img).attr(htmlAttr, htmlObj.replace(new RegExp(pattern, "g"), "//bucket-name.storage.googleapis.com/"));}});});});

完整代码:

var targetUrls = [
    "//" + window.location.host + "/wp-content/uploads/",
    "//" + window.location.host + "/_ah/gcs/bucket-name/"
];
var htmlAttributes = ["src", "srcset"];
jQuery("img").each(function(index, img) {
    targetUrls.forEach(function(pattern) {
        htmlAttributes.forEach(function(htmlAttr) {
            var htmlObj = jQuery(img).attr(htmlAttr);
            if (htmlObj) {
                jQuery(img).attr(htmlAttr, htmlObj.replace(new RegExp(pattern, "g"), "//bucket-name.storage.googleapis.com/"));
            }
        });
    });
});

我认为您需要包含存储桶名称:

    localhost:port/_ah/gcs/bucket_name/file_suffix 

默认端口为8080,文件写入:/bucket_name/file_suffix

您似乎去了:

   http://localhost:8080/_ah/gcs/leanplum-black.svg

但需要包含存储桶名称,可能是 leanplum-wordpress:

   http://localhost:8080/_ah/gcs/leanplum-wordpress/leanplum-black.svg

请注意,我没有在文档中的任何地方找到它。这个问题帮助我猜测我需要在 url 中包含存储桶名称,所以我希望这对其他人也有帮助!