Delete Files from Google Cloud Storage
Question: So I've got a django application up and running on appengine and have it
creating files when a user uploads them. The issue I'm having is trying to
figure out how to delete them. My code for creating them looks like.

    
    
    from google.appengine.api import files
    
    file = request.FILES['assets_thumbnail']
    filename = '/gs/mybucketname/example.jpg'
    writable_file_name = files.gs.create(filename, mime_type='image/jpeg', acl='public-read')
    with files.open(writable_file_name, 'a') as f:
        f.write(file.read())
    files.finalize(writable_file_name)
    

This works fine, but in the documentation at:

<https://developers.google.com/appengine/docs/python/googlestorage/functions>

there isn't a delete method listed. However, if you look at the actual source
for google.appengine.api.files at the link below (line 504)

<http://code.google.com/p/googleappengine/source/browse/trunk/python/google/appengine/api/files/file.py>

There is a delete method that I can call, but I can't figure out for the life
of me exactly the argument it wants. I've tried plenty of different
combinations with the bucket name and such. It seems to want it to start with
/blobstore/ which is different than anything else I've done so far when
interacting with Cloud Storage. I've been looking through the underlying
blobstore classes that google.appengine.api.files is written on top of, but
still can't figure out exactly how to delete items. It looks like I may need
to find the BlobKeys for the items I've uploaded. I can delete them fine using
the web based bucket manager that google hosts and also the gsutil command
line utility that they provide.

Has anyone successfully deleted files from google cloud storage via a python
app deployed to app engine? Any clues/thoughts/ideas are greatly appreciated.


Answer: AppEngine release 1.7.0 has support for deleting Google Storage objects using
bigstore API.

    
    
    key = blobstore.create_gs_key('/gs/my_bucket/my_object')
    blobstore.delete(key)
    

Alternatively, you can use the rest API to make a call out to Google Storage
to delete the file.

<https://developers.google.com/storage/docs/reference-methods#deleteobject>

