TouchDB has a simple garbage collection method which finds files not referenced in the attachments table any more and removes them. I'd be inclined to go down that route.