Get File Object from fileId

Hi,

My App need to access the a file preview (image thumbnail or mimetype icons). From filecache table I can obtain the mimetype, and thus get the icon. The problem is how to get the image thumbnail.

PreviewManager class has a getPreview method, which expects a File $file as argument.

I’m stuck right here: how can I load a File object from file id (or path) ?

best,
alan

\OC::$server->getRootFolder()->getById() should do the trick

Hi Nick,

Thanks a lot for the tip!

In the meanwhile, I found out a simpler way of getting the preview, using

$preview_path = $rootURL . "index.php/core/preview.png?file=%2F" . $file_path . "&x=64&y=64"; 

The drawback of this method is that it looks like the preview is generated on the fly, so it takes a while for loading.

Regarding your suggestion,

\OC::$server->getRootFolder()->getById( $fileId )

returns me an array of OC\\Files\\Node\\File $file .

If I make

$this->previewManager->getPreview($file)

I get back an OC\\Files\\SimpleFS\\SimpleFile object. With this object, I would have to create a preview file, which turns out beeing the same as I described above. Is this right?

Is this the right way of getting an image file preview?

best,
alan