0

The problem I have is the reverse of the one mentioned in this question: Get Public URL for File - Google Cloud Storage - App Engine (Python)

I have the public (serving) URL for an image uploaded to Google Cloud Storage via my Google App Engine Python application. Unfortunately through a yet undetected bug, a record in my database associating the blobstore key (I used blobstore.create_gs_key) and Cloud Storage object and serving URL, was not created.

Now I need to delete that image and all I have is the serving URL, and I need a Cloud Storage object for that.

Any idea if it is possible to get it?

Daniel Ocando
  • 3,554
  • 2
  • 11
  • 19
Michael
  • 1,851
  • 4
  • 19
  • 26

1 Answers1

0

After inspecting the Blobstore Python API on Github I don't think the API offers an easy programatic method to achieve your specific request.

A possible workaround I could think of is that since you have the Cloud Storage URI and most likely know the bucket name to simply search for orphan blobs on the bucket and delete them. You can find an example on the community here.

Finally, I'd like to advise you to use the App Engine client library for Cloud Storage instead of Blobstore Python API as suggested on this latter documentation.

Daniel Ocando
  • 3,554
  • 2
  • 11
  • 19
  • Yea, I suspect you are right and what I want is not possible. Searching for an orphan is not really practical - millions of images down there. I do want to rewrite our image server, eyeing new GAE with python 3 and relational database instead of Google datastore. – Michael Nov 29 '19 at 13:14
  • That final option would be the optimal way to go taking into the consideration the [deprecation of Python 2 since January 1 2020](https://www.python.org/doc/sunset-python-2/). Take into consideration that the documentation offers some very useful insights for migrations from Python 2 to Python 3 for App Engine. You can take a look [here](https://cloud.google.com/appengine/docs/standard/python/migrate-to-python3/) – Daniel Ocando Nov 29 '19 at 13:49