0

Most references seem to read files using PHP functions like file_get_contents(), fgets(), fread(), or readfile().

Is there is any Drupal API that allows to read uploaded files independent of underlying storage?

We are using AWS S3 as our file field storage. Our ec2 instance is in a private subnet with an interface to S3 services. Say the URI is s3://bucketname/object.csv. I need a Drupal API that does an s3 getObject() SDK call under the hood that way I don't get blocked on network level instead request goes through the S3 network interface.

2
  • Please tag the question with the major Drupal version, like 7 or 10.
    – mona lisa
    Commented Mar 2 at 17:34
  • Sorry. This is for Drupal 10.
    – Sivaji
    Commented Mar 4 at 5:05

1 Answer 1

1

Drupal implements access to managed files through stream wrappers. So you can access files using native PHP functions as follows.

file_get_contents('public://some/public/file.txt');
file_get_contents('private://some/private/file.txt');
file_get_contents('temporary://some/temporary/file.txt');
3
  • Thanks. There is a nuance here. We are using AWS S3 as our file field storage. Our ec2 instance is in a private subnet with an interface to S3 services. Say the URI is s3://bucketname/object.csv. I need a Drupal API that does an s3 getObject() SDK call under the hood that way I don't get blocked instead request goes through the S3 network interface.
    – Sivaji
    Commented Mar 4 at 5:03
  • 1
    The S3 module defines a stream wrapper for s3://. Whether that does what you specifically want under the hood you'd have to check, but I think that's the only existing implementation out in the wild that's been battle-tested
    – Clive
    Commented Mar 5 at 14:59
  • @Clive, sure. I will try and let you know.
    – Sivaji
    Commented Mar 7 at 13:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.