I am trying to read the mask.json
from a site_package and use that to generate an api response using an extension like nnrestapi
this is the code i currently have
$filePath = "EXT:site_package/Configuration/Mask/mask.json";
$resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
$file = $resourceFactory->retrieveFileOrFolderObject($filePath);
$fileContent = $file->getContents();
// do something with $fileContent
but I am getting this error
Tried to access a private resource file "EXT:site_package/Configuration/Mask/mask.json" from fallback compatibility storage. This storage only handles public files.
How can I access that file? Is there a better way? Maybe to edit the site_package directly?
I am trying to read the mask.json
from a site_package and use that to generate an api response using an extension like nnrestapi
this is the code i currently have
$filePath = "EXT:site_package/Configuration/Mask/mask.json";
$resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
$file = $resourceFactory->retrieveFileOrFolderObject($filePath);
$fileContent = $file->getContents();
// do something with $fileContent
but I am getting this error
Tried to access a private resource file "EXT:site_package/Configuration/Mask/mask.json" from fallback compatibility storage. This storage only handles public files.
How can I access that file? Is there a better way? Maybe to edit the site_package directly?
Share Improve this question asked Feb 7 at 7:51 Bernd StorathBernd Storath 31 bronze badge2 Answers
Reset to default 2There are several options:
- Move the file into a public area, like fileadmin or
Resources/Public
of your sitepackage (not recommended as "everybody" can access your Mask configuration and therefor can use the information for hacking). Be aware to edit the settings of mask to tell the system that the file is in a new location. - Use a simple
file_get_contents()
to read the JSON file in the API and output it (best solution as you can secure your requests so not everybody can access it). You also can change / remove sensible information in this process - Copy the file into a public area (your information wouldn't be up-to-date)
Would be nice to read why you want to access this file via API? What is the purpose? Maybe there is a much better way?
I solved it by using this code
$absolutePath = GeneralUtility::getFileAbsFileName('EXT:site_package/Configuration/Mask/mask.json');
$fileContent = file_get_contents($absolutePath);