Clearing AppBanner BlobStore

There are a lot of orphan blobs in my AppEngine server that are not used in BlobStore. I would like to write code to iterate over all blobs and check if they are not being used and then delete. I can't seem to find a way to iterate over BlobStore. Is it possible?

+3


source to share


2 answers


You can list https://cloud.google.com/appengine/docs/go/blobstore/reference#BlobInfo via a datastore request (although such a request is ultimately agreed upon).



+1


source


Here is a code-behind 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 will also need to use this function to ignore field mismatch errors:



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

      

}

0


source







All Articles