FIX: create encodeAttachment method