Ben Marten Ben Marten - 2 months ago 19
Python Question

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

I am trying to access files that are hosted on a remote cloud storage bucket through the

dev_appserver.py
dev server.

This direct link to google cloud storage works:

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


where as the local via the dev_appserver does not:

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


Log Output:

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


I am running the dev server like this:

dev_appserver.py --default_gcs_bucket_name=leanplum-wordpress .


What's wrong?

Answer

We're still having this issue. We believe this is an issue that's originating from the Appengine Wordpress plugin.

We came up with the following workaround to get the images loading properly:

Create a Bookmarklet in Google Chrome and add the following 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/"));}});});});

Full Code:

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/"));
            }
        });
    });
});