Access Private File In REST With Base64 Encode

I am facing issue with Private Field, 

  • In my site for anonymous user don’t have any access to view a content, Its headless Drupal.
  • So we have created web services to serve data to other application.
  • In Some content type, I have file attachment. so for file attachments, if I give file URI that URI is not accessible to an anonymous user it will show access denied
  • So to avoid this case I have created new web service to serve the file in encode formate by using “fid”.
  • By using file id, I was loading all file related details and by using file URI converting the file into base 64 encode formate and sending all data in response. This is working fine for small size files.
  • If I upload a pdf file of 10 MB it’s not encoding that file and getting a blank response.
  • I have changed all php.ini setting respect to upload_max_size.

I need a suggestion for implementing such functionality, or the different ways through we can achieve this.

Drupal version: 


Source: https://www.drupal.org/taxonomy/term/4/feed