While performing a contentRepository.Save(media, SaveAction.Publish) I encountered some errors with corrupted files, unable to open the saved documents from EPi. Attempting to download the files in the File Manager of EPiServer resulted in download errors.
Access was denied to content xxx. The required access level was “Create, Publish”
Turns out I need to specify the minimum access requirements for the save operation for it to be successful (never investigated the greater details behind this), and the following change worked out just fine:
contentRepository.Save(media, SaveAction.Publish, AccessLevel.NoAccess)
AccessLevel.NoAccess defines the minimum access level required to view the files.