Store details of Blobkey for images stored in google cloud storage

132 Views Asked by At

I am trying to migrate an application from the google app engine standard environment first generation(python 2.7 runtimes) to second-generation ( python 3 runtimes).

The application serves the user-specific images stored in google cloud storage(previously blob storage). I have completed most of the migration as mentioned in the migration guide provided by Google.

I am facing the following challenges:

  1. I am not able to find any specific way of creating blob key for blobs stored in google cloud storage. In the previous generation, I could use create_gs_key but that functionality seems removed.
  2. Old application has stored image detail in the form of ndb.BlobKeyProperty() how I can migrate these to cloud storage and retain the information. For the previous generation, I could use the GoogleAppEngineCloudStorageClient library.

Current stack:

  • google app engine : python 3 runtime, flask HTML, jquery, javascript

Old stack:

  • google app engine : python 2.7 runtime, webapp2, HTML, jquery, javascript

Disclaimer:

  • Google does provide the option to use app engine APIs in python 3 runtimes by enabling appengine apis in app.yaml but it seems this functionality might be removed at any time.
  • I do not want to keep the application permanently on python 2.7 using docker.
  • Apart from images API, I am not using any other legacy google app engine service.

I might have missed something so feel free to correct me.

EDIT 1:

  1. As mentioned, I have an old application that has blob_key indicating the blob key for stored images, if in the current version I have to use the file name directly I will have to either migrate the images stored in the form of blob key to google cloud storage, make changes to the model( I am trying to avoid this unless and until I don't have any other option)

  2. If I understand correctly, google.appengine.api.blobstore.blobstore is deprecated and using blob store methods is discouraged(Correct me if I am wrong).

1

There are 1 best solutions below

0
Niklas Rosencrantz On

I've been through almost the same problem: My GAE app was written with python2.7 and the API for that which was deprecated. What I did was create a completely new app with python3 and Flask, giving it the public api endpoint api.{{my domain}}.com. When a request comes for the images of an item, I invoke the legacy python2.7 version of my app and write it back to the new one. It isn't elegant but it was the best that I could do.

item = get_item(item_id)    
q = Image.query()
data = q.filter(Image.reference == item.key)
data = data.fetch(5)

for i in data:  
    # get the image from legacy and write it to new
    x_list = reqs.get(f"https://legacy.myapp.com/imgs/{item_id}").content
    l_json = json.loads(x_list)
    item.images = []
    for img_url in l_json.get("imgs"):
        img_data = reqs.get(img_url).content
        identity = str(uuid.uuid4())
        try:
            io_img_data = io.BytesIO(img_data)
            upload_blob("mynew_app.appspot.com", io_img_data, identity)