Store before closing file

Attachment uploads were failing because file handle was closed already
when attachment upload was being transmitted