# How can I get all the information about a asset?

**URL:** <https://discourse.getcockpit.com/t/how-can-i-get-all-the-information-about-a-asset/1742>\
**Category:** Uncategorized\
**Created:** [December 9, 2020, 7:14am UTC](https://discourse.getcockpit.com/t/how-can-i-get-all-the-information-about-a-asset/1742 "2020-12-09T07:14:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![xxge](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/xxge/32/634_2.png) [@xxge](https://discourse.getcockpit.com/u/xxge)\
**Post date:** [December 9, 2020, 7:14am UTC](https://discourse.getcockpit.com/t/how-can-i-get-all-the-information-about-a-asset/1742/1 "2020-12-09T07:14:57Z")

</div>

I have a collection that has a field of type image.

For example:

```
[
	{
		"image" : {
			"path":"\/cockpit\/storage\/uploads\/2020\/12\/08\/image.png"
		},
		"_mby":"5fa40497363238bd460000fe",
		"_by":"5fa40497363238bd460000fe",
		"_modified":1607497476,
		"_created":1607497476,
		"_id":"5fd07704393966912a0001f2"
	}
]

```

How can I get all the information about a asset? The problem is that I don’t have a asset id.

```
$app->storage->findOne('cockpit/assets', ['_id' => /* asset id */]);
```

---

<div class="post-metadata">

**Author:** ![raffaelj](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/raffaelj/32/331_2.png) [@raffaelj](https://discourse.getcockpit.com/u/raffaelj)\
**Post date:** [December 10, 2020, 12:08pm UTC](https://discourse.getcockpit.com/t/how-can-i-get-all-the-information-about-a-asset/1742/2 "2020-12-10T12:08:10Z")

</div>

You have to remove `/cockpit/storage/uploads` from the path and than you can query the database with:

```php
$asset = $app->storage->findOne('cockpit/assets', ['path' => '/2020/12/08/image.png']);

```

I had the same problem before and solved it [here](https://github.com/raffaelj/CpMultiplane/blob/master/modules/Multiplane/Controller/Base.php#L114-L118).

This should work (not tested):

```php
// img src: /cockpit/storage/uploads/2020/12/08/image.png

$src = $entry['image']['path'];

// remove `/storage/uploads` from image urls
$uploads = \str_replace(COCKPIT_ENV_ROOT, '', $app->path('#uploads:'));
if (\strpos($src, $uploads) === 0) {
    $src = \substr($src, \strlen($uploads));
}

// eventually same result as above, not tested
//$src = $app->pathToUrl($app->path('#uploads:'));

// img src is now: /2020/12/08/image.png

$asset = $app->storage->findOne('cockpit/assets', ['path' => $src]);

print_r($asset);

```

---

<div class="post-metadata">

**Author:** ![xxge](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/xxge/32/634_2.png) [@xxge](https://discourse.getcockpit.com/u/xxge)\
**Post date:** [December 12, 2020, 11:24am UTC](https://discourse.getcockpit.com/t/how-can-i-get-all-the-information-about-a-asset/1742/3 "2020-12-12T11:24:43Z")

</div>

Thank you! 🙂
