Get file information like path, mimtype, permission for many fileId's

Dear Nextcould developer community,
I have a big list of fileId’s and need to get the remaining Information for those file. Currently I’m doing

foreach ($fileIds as $fileId) {
				 $cacheEntry = $cache->get($fileId);
				 if ($cacheEntry) {
					 // this path is relative to owner's storage
					 //$path = $cacheEntry->getPath();
					 //but we want it relative to current user's storage
					 $files = $folder->getById($fileId);
					 if (empty($files)) {
					 $file = array_shift($files);
					 if ($file === null) {
					 $path = $userFolder->getRelativePath($file->getPath());
					 $isIgnored = false;
					 foreach ($ignoredPaths as $ignoredPath) {
						 if (str_starts_with($path, $ignoredPath)) {
							 $isIgnored = true;
					 if (!$isIgnored) {
						 $isRoot = $file === $userFolder;

						 $file_object = new \stdClass();
						 $file_object->fileId = $fileId;
						 $file_object->fileid = $file_object->fileId;
						 $file_object->basename = $isRoot ? '' : $file->getName();
						 $file_object->filename = $this->normalizePath($path);
						 $file_object->etag = $cacheEntry->getEtag();
						 //Not working for NC21 as Viewer requires String representation of permissions
						 //                $file_object->permissions = $file->getPermissions();
						 $file_object->type = $file->getType();
						 $file_object->mime = $file->getMimetype();
						 $file_object->lastmod = $file->getMTime();
						 $file_object->size = $file->getSize();
						 $file_object->path = $path;
						 $file_object->isReadable = $file->isReadable();
						 $file_object->isUpdateable = $file->isUpdateable();
						 $file_object->isShareable = $file->isShareable();
						 $file_object->isDeletable = $file->isDeletable();
						 $file_object->hasPreview = in_array($cacheEntry->getMimeType(), $previewEnableMimetypes);
						 $filesById[] = $file_object;

This results into at-least one DB query per FileId. I have multipe thousands to multiple 10 thousands and therefore lots of Queries are executed.

What is the proper way to reduce those Queries? Can I directly query the filecache table?
Is there any function like getFilesByIds ?


There is a file metadata app. Is that what you are looking for?

No, I’m trying to get the usual File information like size, mimetype and the permissions.
And the problem is not to get these Information for a single file. I’m looking for a bulk method to get this for many files.

I understand. No there is no such feature. In truth I do beleive there is also enterprise customer who could greatly benefit from an API in order to DAG.

1 Like

Actually I think I am not entirely correct. This could be easily dumped/queried from the database.