清理AppEngine BlobStore

My AppEngine server has a lot of orphaned blobs not used in the BlobStore. I'd like to write code to iterate over all the blobs and check if they are not being used and then delete. I can't find a way to iterate over the BlobStore. Is this possible?

You can list the https://cloud.google.com/appengine/docs/go/blobstore/reference#BlobInfo via a datastore query (though such query is eventually consistent).

Here is a code solution for iterating over blobs in golang:

c.Infof("Iterating over blobs")
q := datastore.NewQuery("__BlobInfo__")

// Iterate over the results.
total := 0
t := q.Run(c)
for {
        var bi blobstore.BlobInfo
        _, err := t.Next(&bi)
        if err == datastore.Done {
                break
        }
        if err != nil && isErrFieldMismatch(err) == false {
                c.Errorf("Error fetching next Blob: %v", err)
                break
        }
        // Do something with the Blob bi
        c.Infof("Got blob [%v] of size [%v]", bi.ContentType, bi.Size)
        total++
        if total > 100 { break }
}
c.Infof("Iterating Done")

You'll also need to use this function to ignore field mismatch errors:

func isErrFieldMismatch(err error) bool {
    _, ok := err.(*datastore.ErrFieldMismatch)
    return ok

}