My app works fine when Nextcloud has all files stored on local storage, on the serverâs hard drive. However, when a user configures his Nextcloud to use remote storage, like Amazonâs S3, my app throws multiple errors caused by file_get_contents() not finding the file.
With local storage I can get file content like this:
This method uses the path relative to the data directory. It works fine with local storage, but with remote storage, the file is not actually in that path, in the âdataâ directory. So, that path becomes invalid and file_get_contents()fails. Even an absolute path like /var/www/nextcloud/data/username/files/my_app/temp_dir/ . $filename wouldnât work, because, as I said, with remote storage, the file isnât actually there. Nextcloud stores the path to the remote file in the database and maps that path to the regular Nextcloud path.
To solve this problem I would use the file_get_contents method of the Filesystem class which uses paths relative to the Nextcloud base directory, like this:
In this way, I used paths relative to the âAll filesâ folder (root folder) for every user and consequently, even if Nextcloud used remote storage and the files were not located inside the /var/www/nextcloud/data/username/files directory of each user, the mentioned functions worked.