I'm trying to let Customer Community users upload and retrieve files on cases. I've done this using Chatter Files before, on a custom object that had it's sharing set to private (because it was a in a master-detail relationship with a private object) without any problems.
I then insert the ContentVersion object and create a new FeedItem with Type 'ContentPost', ParentId the Id of the case I want to add it to and RelatedRecordId the Id of the ContentVersion I inserted earlier.
However, at the very last step, inserting the FeedItem throws an error saying 'INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY'. I found that turning the FeedItem into a TextPost instead of ContentPost and removing the RelatedRecordId stops this from happening, so I'm assuming the problem isn't with Case permissions. The only other variable is the ContentVersion object, which is owned by the Community User so should technically be completely accessible.
I even tried substituting the case Id for the Id of one of the custom objects I was able to do this with before, and still it doesn't work. Is there anything I'm somehow still overlooking?
EDIT: I've tried enabling Case Feed and Case Feed for Communities, but no change in behaviour. I've also tried creating a CaseFeed Item directly, but its fields are not writable.