Abstract FoiAttachment conversion to library

Continuing from #1399