'Optimized way of restricting access to images in backend

I am working on an app that has some social network elements: users can create posts with images and they can share these publicly or with friends.

I am now considering the security aspect of this. These images should only be available to the person that uploaded them and the people they select to view them.

From the posts I have seen it seems that one of the recommended ways is to expose an API endpoint through my backend service to control access through it (this way I can check a user's permissions) and then return the requested image but I feel that serving images this way would be quite expensive.

Are there any other approaches that do not sacrifice security but achieve a good performance?

In case it matters, I am using Spring Boot for my backend, Expo + React Native for my app and I am planning to store the images on AWS S3



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source