Extract FoiAttachment conversion to library

Continuing from #1399