To attach image use next code
DocuRef docuRef = DocumentManagement::attachFile( inventTable.TableId, inventTable.RecId, curext(), DocuType::typeImage(), memoryStream, fileName, null, description); if (docuRef) { EcoResProductImage::create(docuRef); }