See:
Why does adding a Queueable cause an INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY error?
for some background. That results in the need to set the NetworkId (there is one of these per Community) on the ContentVersion object.
Passing that Id explicitly can be awkward, and given the NetworkMember object, a query:
select NetworkId from NetworkMember where select MemberId = :UserInfo.getUserId()
will return the zero or more relevant NetworkIds.
In my experience, a Username is unique to a Community, meaning the above would return the required single NetworkId. But are there other Community setups where the same UserId applies to more than one Community?
NetworkMemberas there are communities the user has access to for a singleMemberId. It's as simple as Jefferson mentioned with his link for a given profile/permission set. You might have to add another filter, technically, likeNetwork.Nameto be absolutely certain it's the right one or re-evaluate whether passing NetworkId might be the best option. – Kris Goncalves Mar 10 '21 at 12:23